How to Get total and Current Slide Number of Carousel

前端 未结 7 1408
野的像风
野的像风 2020-12-07 20:58

Can you please let me know how I can get the total and current number of the carousel slides in bootstrap like the image below?

7条回答
  •  轮回少年
    2020-12-07 21:40

    var totalItemsPop = $('#Mycarousel .item').length; 
    $('#Mycarousel').on('slide.bs.carousel', function() {
           setTimeout(function(){ 
                currentIndexPop = $('#Mycarousel div.active').index() + 1;
                $('.num').html('' + currentIndexPop + '/' + totalItemsPop + '');
             }, 1000);
       });
    

    after slide event, div will be active and can not get active index, so keep your code inside set time out function

提交回复
热议问题