I am using bootstrap carousel in my website. But I want its functionality little different. I want slides to change on mouseScroll (each slide on each time mouse scrolled).
How can I achieve it with Bootstrap Carousel?
JavaScript
x
4
1
$('#myCarousel').carousel({
2
interval: 3000
3
});
4
Advertisement
Answer
$('#myCarousel').carousel('next')
slides to next item as documented.
So you can bind scroll event to do that:
JavaScript
1
4
1
$('#myCarousel').bind('mousewheel', function() {
2
$(this).carousel('next');
3
});
4
Edit: you can get mouse wheel events and make carousel move to next or previous slide:
JavaScript
1
8
1
$('#myCarousel').bind('mousewheel', function(e) {
2
if(e.originalEvent.wheelDelta /120 > 0) {
3
$(this).carousel('next');
4
} else {
5
$(this).carousel('prev');
6
}
7
});
8
updated your jsfiddle
You can also bind it to all carousels instead of a specific single one by using a class selector: Use $('.carousel').bind(...)
for that. If your requirement is to have all your carousels support the mouse wheel, not just a specific single one, the class selector is more convenient.