Fire event on Bootstrap carousel slide issue

22,825

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.

Share:
22,825
sdvnksv
Author by

sdvnksv

Updated on July 05, 2022

Comments

  • sdvnksv
    sdvnksv almost 2 years

    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);
    });
    
  • sdvnksv
    sdvnksv over 10 years
    it works in Chrome, but fails to work in Mozilla. Any suggestions?
  • sdvnksv
    sdvnksv over 10 years
    Yes, it turned out that Mozilla has problems with animate(backgroundPositionX). I managed to fix it with a plugin. Now it works fine.
  • Pupil
    Pupil over 7 years
    I have searched everywhere for this question and finally got this answer. Thanks.