Fire event on Bootstrap carousel slide issue

sdvnksv picture sdvnksv · Nov 21, 2013 · Viewed 21.1k times · Source

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);
});

Answer

ringstaff picture ringstaff · Nov 21, 2013

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.