Fire event on Bootstrap carousel slide issue
Asked Answered
C

1

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);
});
Clotho answered 21/11, 2013 at 18:38 Comment(0)
D
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.

Dihedron answered 21/11, 2013 at 20:44 Comment(3)
it works in Chrome, but fails to work in Mozilla. Any suggestions?Clotho
Yes, it turned out that Mozilla has problems with animate(backgroundPositionX). I managed to fix it with a plugin. Now it works fine.Clotho
I have searched everywhere for this question and finally got this answer. Thanks.Korikorie

© 2022 - 2024 — McMap. All rights reserved.