Getting Index of Current Item in JCarousel

前端 未结 11 1713
夕颜
夕颜 2021-02-05 20:25

I am attempting to get the index of the current item in a JCarousel so that I can display the current position within the Carousel to the user. For example, \'13/20\'.

H

11条回答
  •  醉酒成梦
    2021-02-05 20:40

    var jcarousel = $('.jcarousel').on('jcarousel:createend', function(event, carousel) {
                      do_something_with_current_slide(carousel); //in case if you need current slide on the begining
                  })
                  .on('jcarousel:animateend', function(event, carousel) {
                      do_something_with_current_slide(carousel); //do something with current slide right after animation ends
                  })
                  .jcarousel({
                        wrap: 'circular'                    
                  });
    
    function do_something_with_current_slide(carousel){
        li = carousel._target;  //li of current slide
        alert(li.attr('slide')); 
    }
    

    you can use any number of attributes to indentify slide and data inside

提交回复
热议问题