Custom Carousel Intervals?

后端 未结 2 1464
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-07 06:22

In Bootstrap 3, with jQuery is there a way to sort by the index of my carousel and add custom intervals of each slide so that I can have one slide 10000ms and another 500ms

2条回答
  •  天涯浪人
    2021-01-07 07:04

    You can create a custom attribute that denotes how long the slide should be visible for, pull that out for the active item on the slide.bs.carousel or slid.bs.carousel events (whichever you prefer/works best for you), then set it as a timeout to go to the next slide.

    $('#carousel-example-generic').on('slide.bs.carousel', function() {
      var interval = $('div.item.active').attr('duration');
      setTimeout(function() {
        $('.carousel').carousel('next');
      }, interval);
    });
    
    
    
    
    
    

提交回复
热议问题