12

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);
});
kjhughes
  • 106,133
  • 27
  • 181
  • 240
sdvnksv
  • 9,350
  • 18
  • 56
  • 108

1 Answers1

32

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.

Community
  • 1
  • 1
ringstaff
  • 2,331
  • 1
  • 16
  • 25
  • it works in Chrome, but fails to work in Mozilla. Any suggestions? – sdvnksv Nov 22 '13 at 14:33
  • Yes, it turned out that Mozilla has problems with animate(backgroundPositionX). I managed to fix it with a plugin. Now it works fine. – sdvnksv Nov 24 '13 at 06:16
  • I have searched everywhere for this question and finally got this answer. Thanks. – Pupil Oct 27 '16 at 02:58