How to Get total and Current Slide Number of Carousel

前端 未结 7 1423
野的像风
野的像风 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:18

    Update of @Khawer Zeshan's code

    For Bootstrap 3.0+ use slid.bs.carousel instead of slid and on instead of bind . So the update code will be like that

    var totalItems = $('.item').length;
    var currentIndex = $('div.active').index() + 1;
    
    $('#myCarousel').on('slid.bs.carousel', function() {
        currentIndex = $('div.active').index() + 1;
       $('.num').html(''+currentIndex+'/'+totalItems+'');
    });
    

提交回复
热议问题