Removing an item from jCarousel plug-in

前端 未结 5 993
臣服心动
臣服心动 2020-12-17 06:27

I have a question regarding the jCarousel plug-in (from sorgalla). How do I remove items from it the right way?

You can see how far I\'ve gone here. Try deleting a

5条回答
  •  忘掉有多难
    2020-12-17 06:51

    $.jcarousel.fn.extend({
        removeAndAnimate: function(index) {
    
            var itemsHTML = new Array();
            var counter = 0;
    
            // Me guardo los que quedan
            for(i = 0; i < this.size(); i++)
            {
                if(i != (index - 1))
                    itemsHTML[counter++] = $('li[jcarouselindex|="' + i + '"]').html();
            }
    
            // Configuro uno menos y borro todo
            this.size(this.options.size -1);
            this.reset();
    
    
            // Vuelvo a cargarlos
            counter = 0;
            for(i = 0; i < itemsHTML.length; i++)
            {
                this.add(counter++, itemsHTML[i]);
            }
    
            this.reload();
        }
    });
    

    USAGE

    var carousel = jQuery('#mycarousel').data('jcarousel');
    carousel.removeAndAnimate(1);
    

提交回复
热议问题