Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 hebrew/arabic websites?

like image 596
Adam Tal Avatar asked Jun 01 '13 21:06

Adam Tal


1 Answers

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();
    });
});
like image 174
Adam Tal Avatar answered Sep 28 '22 08:09

Adam Tal