最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Trigger an event on specific slide - Bootstrap Carousel - Stack Overflow

programmeradmin1浏览0评论

Ok, so I need to trigger an event when specific (let's say number 2) slide is displayed. I've checked this function:

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

/

but in the console there's no information what slide is displayed. How to get the actuall number of slide? Anyone can help?

Ok, so I need to trigger an event when specific (let's say number 2) slide is displayed. I've checked this function:

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

http://jsfiddle/9fwuq/380/

but in the console there's no information what slide is displayed. How to get the actuall number of slide? Anyone can help?

Share Improve this question asked Jan 15, 2015 at 12:01 DavidDavid 1,9633 gold badges27 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

You can use this event instead and following logic: {maybe better way, check the 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-

see this. http://jsfiddle/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++;
    });

you just need to put a condition to check the number of current slide. in the example given above, i am checking each time the first slide.[assuming the count starts from 00].

发布评论

评论列表(0)

  1. 暂无评论