kaleem
kaleem

Reputation: 59

Bootstrap carousel doesn't start on-load and sliding stops with hover

I have this code in HTML. The whole section is in id="main-slider". The carousel doesn't slide unless I click on the arrow and it works perfectly after that. Another problem which I'm facing is that the slider is a full page slider. By default, bootstrap stops sliding when hovered. I do not want this effect to take place. To solve both, I gave the jQuery function to overwrite this, but nothing seems to work. After spending 6 hours reading and trying almost everything in Github and at this place, finally decided to get help here.

    <section id="main-slider">
    <div class="carousel slide">
      <ol class="carousel-indicators ">
        <li class="active" data-slide-to="0" data-target="#main-slider"></li>
        <li data-slide-to="1" data-target="#main-slider"></li>
        <li data-slide-to="2" data-target="#main-slider"></li>
        <li data-slide-to="3" data-target="#main-slider"></li>
      </ol>
    <div class="carousel-inner">
      <div class="item active" style="background-image: url(images/slider1.jpg)">
        <div class="container">
          <div class="row">
            <div class="col-sm-12">
              <div class="carousel-content centered">
                <div class="center" id="text-position"> <!-- self defined class in css-->
                  <h2></h2>
                    <p></p>
                      <a class="btn btn-md-primary></a>
                </div> <!-- /center -->
              </div> <!-- /carousel-content -->
            </div> <!-- /col-sm -->
          </div> <!-- /row -->
        </div> <!-- /container -->
      </div> <!-- /item active -->
    <!--I have 3 more similar rows-->
    </div> <!-- carousel ends -->

    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/main.js"></script>
    <script>
    $(function(){
    $('#main-slider.carousel').carousel({
        interval: 2000,
        pause: false
        });
    });
   </script>

Upvotes: 0

Views: 5199

Answers (1)

simonhamp
simonhamp

Reputation: 3329

Instead of using the Javascript initialiser, have you tried using the data- attributes method? e.g.

<div class="carousel slide wet-asphalt" data-ride="carousel" data-interval="2000" data-pause="false">

Don't forget to remove your Javascript initialiser.

Upvotes: 6

Related Questions