Twitter Bootstrap Carousel cycle items right to left ( RTL ) reversed

后端 未结 5 1643
慢半拍i
慢半拍i 2020-12-03 22:57

How can the Twitter Bootstrap Carousel cycle function can be changed to cycle the items from right to left instead of left to right so it\'ll look normal in

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 23:27

    Just override the cycle function with a similar function that calls prev instead of next:

    $(document).ready(function () {
        $('.carousel').each(function(){
            $(this).carousel();
    
            var carousel = $(this).data('bs.carousel'); // or .data('carousel') in bootstrap 2
            carousel.pause();
    
            // At first, reverse the order of the items in the carousel because we're moving backwards
            $(this).find('> .carousel-inner > .item:not(:first-child)').each(function() {
                $(this).prependTo(this.parentNode);
            });
    
            // Override the bootstrap carousel prototype function, adding a different one won't work (it'll work only for the first slide)
            carousel.cycle = function (e) {
                if (!e) this.paused = false
                if (this.interval) clearInterval(this.interval);
                this.options.interval
                && !this.paused
                && (this.interval = setInterval($.proxy(this.prev, this), this.options.interval))
                return this;
            };
    
            carousel.cycle();
        });
    });
    

提交回复
热议问题