Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap JavaScript Carousel Doesn't Stop Cycling

Twitter Bootstrap Version: 2.0.3

Example HTML code:

<!DOCTYPE html> <html dir="ltr" lang="en-US" xmlns:og="http://opengraphprotocol.org/schema/"> <head> <link rel="stylesheet" type="text/css" media="all" href="reddlec/style.css" /> <script type="text/javascript"> $(document).ready(function() {     $('.carousel').each(function(){         $(this).carousel({             pause: true,             interval: false         });     }); });​ </script> <script src="http://twitter.github.com/bootstrap/assets/js/jquery.js"></script> <script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-transition.js"></script> <script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-carousel.js"></script> </head> <body> <div id="myCarousel" class="carousel slide">   <!-- Carousel items -->   <div class="carousel-inner">     <div class="active item">…</div>     <div class="item">…</div>     <div class="item">…</div>   </div>   <!-- Carousel nav -->   <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>   <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a> </div> </body> </html> 

CSS: Provided with bootstrap.css

Problem: As you can see, I've enabled paused mode, and disabled cycling. But when I click the carousel's left or right controls, the carousel starts cycling at the default interval (5 seconds per cycle) on mouseleave.

How do I forcefully disable cycling? I want the images to be cycled manually by the user.

You can test the problem live on my test site here.

like image 837
its_me Avatar asked May 09 '12 17:05

its_me


People also ask

How do I stop bootstrap carousel autoplay?

Now, the first way to stop the autoplay is by just removing the attribute data-ride=”carousel” from the code above. $( '. carousel' ). carousel( 'pause' );

How do I stop carousel from moving automatically?

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

How do I pause bootstrap carousel?

You'll need to call the pause function like this: $("#myCarousel"). carousel('pause'); . This is how all methods are called on bootstrap components, following the jQuery UI convention. You can restart the carousel by listening to the blur event then calling the cycle method.

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.).


1 Answers

You might want to try removing the "pause" attribute. It's not necessary if you are not automatically cycling through the images. My assumption (and I'm going to look at the bootstrap code to verify) is that when the "mouseleave" event fires, the cycling resumes -- even if it was turned off in the first place. When it resumes, it uses the default speed.

Here is a solution:

$(function() {     $('.carousel').each(function(){         $(this).carousel({             interval: false         });     }); });​ 
like image 164
dgabriel Avatar answered Sep 22 '22 05:09

dgabriel