问题
I try to use this code to fire on an event upon carousel slide, but it fails to work for some reason. Any suggestions?
var $carousel = $('#carousel-showcase');
$carousel.carousel();
$carousel.bind('slide', function(e) {
setTimeout( function(){
var left = $carousel.find('.item.active.left');
var right = $carousel.find('.item.active.right');
if(left.length > 0) {
$("#wrap").animate({
backgroundPositionX: '+=50%'
},0);
}
else if(right.length > 0) {
$("#wrap").animate({
backgroundPositionX: '-=50%'
},0);
}
}, 500);
});
回答1:
Bootstrap 3 changed the 'slide' event to 'slide.bs.carousel'. Change to this and it should work (assuming that is your only issue):
$carousel.bind('slide.bs.carousel', function (e) {
console.log('slide event!');
});
See this question.
来源:https://stackoverflow.com/questions/20129290/fire-event-on-bootstrap-carousel-slide-issue