Different slide duration for each item on bootstrap 3.1 carousel

后端 未结 4 1829
[愿得一人]
[愿得一人] 2020-12-01 11:44

I am trying to have different duration for each slide as my some slides have large content and some small please give me a solution with fiddle

I tried this but it o

4条回答
  •  心在旅途
    2020-12-01 11:52

    For some reason, the pause method did seem to work for me. So, I used the following code and it worked for me. This works even if you have multiple carousels on the same page. This approach however requires the data-interval attribute mandatory against each carousel item.

    var t;
    var start = $('#myCarousel').find('.active').attr('data-interval');
    
    t = setTimeout(function () {
        $('#myCarousel').carousel('next')
    }, start);
    
    $('#myCarousel').on('slid.bs.carousel', function () {
    
        clearTimeout(t);
        var duration = $('#myCarousel').find('.active').attr('data-interval');
    
        //$('#myCarousel').carousel('pause');
        t = setTimeout("$('#myCarousel').carousel('next');", duration);
    })
    
    $('.carousel-control.right').on('click', function () {
        clearTimeout(t);
    });
    
    $('.carousel-control.left').on('click', function () {
        clearTimeout(t);
    });
    

提交回复
热议问题