Twitter Bootstrap Carousel - access current index

后端 未结 9 1252
面向向阳花
面向向阳花 2020-12-02 14:11

How do I get the current index from the carousel?

In this case I am using an unordered list. I know I could search through the list items to find the one with the \'

9条回答
  •  借酒劲吻你
    2020-12-02 14:51

    For bootstrap 3 it's

    $('#myCarousel').on('slide.bs.carousel', function (e) {
      var active = $(e.target).find('.carousel-inner > .item.active');
      var from = active.index();
      var next = $(e.relatedTarget);
      var to = next.index();
      console.log(from + ' => ' + to);
    })
    

    from https://github.com/twbs/bootstrap/pull/2404#issuecomment-22362366

提交回复
热议问题