Getting Index of Current Item in JCarousel

前端 未结 11 1711
夕颜
夕颜 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:55

    Another solution getting the current index of the item with jquery...

    //jcarousel item becomes visible
    $('.jcarousel').on('jcarousel:visiblein', 'li', function(event, carousel) {
        // "this" refers to the item element
    
        itemCount = $(".jcarousel li").length; //1 based
        currentIndex = ($( "li" ).index($(this))); //0 based
    
        if(currentIndex + 1 == itemCount) {
            alert('last');
        }
    
        if(currentIndex == 0) {
            alert('first');
        }
    });
    

提交回复
热议问题