According to doco, using the following, the carousel cycle speed will be set:
$('.carousel').carousel({ interval: 2000 })
However, if you have already initialized the carousel, calling the above with a different interval has no effect.
It should be noted that carousel initialization via JS does not set the data-interval on the carousel. I also searched a lot for this topic, but the results are all that people are trying to tune at a fixed speed. I want to change the speed after it is initialized.
The code is as follows:
$(function () { $('#homeCarousel').carousel({ interval:2000, pause: "false" }); $('#slowButton').click(function () { $('#homeCarousel').carousel({interval: 10000}); }); $('#fastButton').click(function () { $('#homeCarousel').carousel({interval: 1000}); }); });
#carouselButtons { margin-left: 100px; position: absolute; bottom: 0px; } .item { color: white; background-color: black; width:100%; height: 350px; }
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/> <link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <div id="homeCarousel" class="carousel slide"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <div class="carousel-inner"> <div class="item active"> <div class="container"> <div class="carousel-caption"> <h1>Bootstrap 3 Carousel Layout</h1> <p>This is an example layout with carousel that uses the Bootstrap 3 styles.</p> <p><a class="btn btn-lg btn-primary" href="http://getbootstrap.com">Learn More</a> </p></div> </div> </div> <div class="item"> <div class="container"> <div class="carousel-caption"> <h1>Changes to the Grid</h1> <p>Bootstrap 3 still features a 12-column grid, but many of the CSS class names have completely changed.</p> <p><a class="btn btn-large btn-primary" href="#">Learn more</a></p> </div> </div> </div> <div class="item"> <div class="container"> <div class="carousel-caption"> <h1>Percentage-based sizing</h1> <p>With "mobile-first" there is now only one percentage-based grid.</p> <p><a class="btn btn-large btn-primary" href="#">Browse gallery</a></p> </div> </div> </div> </div> <a class="left carousel-control" href="#myCarousel" data-slide="prev"> <span class="icon-prev"></span> </a> <a class="right carousel-control" href="#myCarousel" data-slide="next"> <span class="icon-next"></span> </a> <div id="carouselButtons"> <button id="slowButton" type="button" class="btn btn-default btn-xs"> <span class="glyphicon glyphicon-play"></span> </button> <button id="fastButton" type="button" class="btn btn-default btn-xs"> <span class="glyphicon glyphicon-forward"></span> </button> </div> </div>
source share