在特定幻灯片上触发事件 - Bootstrap 轮播

Trigger an event on specific slide - Bootstrap Carousel

好的,所以我需要在显示特定(比如说第 2 张)幻灯片时触发一个事件。我检查了这个功能:

$('#myCarousel').bind('slide.bs.carousel', function (e) {
    console.log($(this));
});

http://jsfiddle.net/9fwuq/380/

但在控制台中没有显示显示的幻灯片的信息。如何获得幻灯片的实际数量?有人可以帮忙吗?

看到这个。 http://jsfiddle.net/naeemshaikh27/9fwuq/382/

   var x=0;
    $('#myCarousel').bind('slide.bs.carousel', function (e) {

        if(x%3==0)
        {
            console.log('slide number');

// trigger you event here
        }
        x++;
    });

你只需要输入一个条件来检查当前幻灯片的数量。在上面给出的示例中,我每次检查第一张幻灯片时都会检查。[假设计数从 00 开始]。

您可以改用此事件并遵循以下逻辑:{也许更好的方法,请查看 DOC}

$('#myCarousel').bind('slid', function (e) {
    var index = $(e.target).find(".active").index();
    if(index === 1) //  (2 - 1) index is zero based
        alert('slide2 displayed!');
})

;

-DEMO-