Bootstrap Carousel Next/prev Not Working
I am working with Twitter Bootstrap Carousel and though I am not very familiar with .js, somehow I got things working fine. The only problem is that the next/prev button is workin
Solution 1:
You handle slider's next/prev buttons with your own handler, so it slide to 2nd element 1st, than tries to make next()
replace:
$("#myCarousel a").click(function(e){
var index = $(this).index();
//when hitting NEXT button index always 2, for PREV - 0
slider.carousel(index);
e.preventDefault();
});
with
$("#myCarousel .slider-pager a").click(function(e){
var index = $(this).index();
slider.carousel(index);
e.preventDefault();
});
in your onpage script
Solution 2:
For future visitors to this question:
Use attribute data-interval="false"
(Bootstrap 3.3.5):
<div id="myCarousel"class="carousel slide" data-ride="carousel" data-interval="false">
Here are other supported carousel options in Bootstrap 3:
http://getbootstrap.com/javascript/#carousel-usage
Earlier versions:
<div id="myCarousel"class="carousel slide text-center" data-ride="carousel">
<olclass="carousel-indicators"><lidata-target="#myCarousel"data-slide-to="0"class="active"></li><lidata-target="#myCarousel"data-slide-to="1"></li></ol><divclass="carousel-inner"role="listbox"><divclass="item active"><h4>A mind-bending lecture on applied philosophy by Oxford lecturer Ravi Zacharias.</h4><br><spanclass="font-normal">youtube/watch?v=3ZZaoavCsYE</span></div><divclass="item"><h4>Director of the Human Genome Project discusses the greatest mystery of life</h4><br><spanclass="font-normal">youtube/watch?v=EGu_VtbpWhE</span></div></div><ahref=""class="left carousel-control"href="#myCarousel"role="button"data-slide="prev"><spanclass="glyphicon glyphicon-chevron-left"aria-hidden="true"></span><spanclass="sr-only">Previous</span></a><ahref=""class="right carousel-control"href="#myCarousel"role="button"data-slide="next"><spanclass="glyphicon glyphicon-chevron-right"aria-hidden="true"></span><spanclass="sr-only">Next</span></a></div><!-- #myCarousel --><script>
$(function(){
$('.carousel-control').click(function(e){
e.preventDefault();
$('#myCarousel').carousel( $(this).data() );
});
});//END document.ready</script>
Note: this answer requires jQuery, so ensure that library is loaded. Of course, bootstrap requires jQuery so you should already have it referenced.
Post a Comment for "Bootstrap Carousel Next/prev Not Working"