Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Carousel Not Automatically Sliding

I'm using bootstrap by Twitter's carousel (latest version) and I've got it working - except that it doesn't begin to automatically slide. It works well after you've clicked one of the navigation buttons . Not sure why it's doing this.

Here's my JS setup in the header:

    <script type="text/javascript" src="<?php echo tz_JS . '/bootstrap/jquery.js'; ?>"></script>

<script type="text/javascript" src="<?php echo tz_JS . '/bootstrap/bootstrap-carousel.js'; ?>"></script>
<script type="text/javascript" src="<?php echo tz_JS . '/bootstrap/bootstrap-transition.js'; ?>"></script>

And the HTML:

<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">

    <div class="active item">
    <div class="image-position-right">
        <a href="#"><img src="validimagelink.jpg" width="920" height="550" alt=""></a>
    </div>
    </div>


    <div class="item">
    <div class="image-position-right">
        <a href="#"><img src="validimagelink.jpg" width="920" height="550" alt=""></a>
    </div>
    </div>

</div>

<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>

Also just added this to no avail:

<script>
$('#myCarousel').carousel({
    interval: 1200
});
</script>

After making the above change, the javascript console says:

Uncaught TypeError: Object # has no method 'carousel' (anonymous function) b.extend.ready jquery.min.js:29 u

Any thoughts on why this wouldn't be working?

like image 718
William H Avatar asked Jun 27 '12 19:06

William H


People also ask

How do I make bootstrap carousel not slide automatically?

$('. carousel'). carousel({ interval: false, }); That will make the auto sliding stop because there no Milliseconds added and will never slider next.

Why is Bootstrap carousel not sliding?

In browsers where the Page Visibility API is supported, the carousel will avoid sliding when the webpage is not visible to the user (such as when the browser tab is inactive, the browser window is minimized, etc.).

How do I turn off autoplay on carousel?

To turn off the autoplay set data-interval="false" to the carousel element.

How do I set the carousel slide time in bootstrap?

You can simply use the data-interval attribute of the carousel class. It's default value is set to data-interval="3000" i.e 3seconds. All you need to do is set it to your desired requirements.


1 Answers

<script type="text/javascript">
  $(document).ready(function() {
    $('.carousel').carousel({
      interval: 1200
    })
  });
</script>

If it still is not working, look for potential errors in the browser's (firebug/chrome..) console.


For

Uncaught TypeError: Object # has no method 'carousel' (anonymous function) b.extend.ready jquery.min.js:29 u

Make sure:

Only one jQuery is included

Only one bootstrap-carousel.js or bootstrap.js is included.

jQuery is included first, then bootstrap-carousel.js or bootstrap.js, then $(document).ready( ...

like image 171
baptme Avatar answered Oct 15 '22 03:10

baptme