skip to Main Content

Good day

I’m editing a project that is using owl carousel, currently the carousel is in random mode, I want to sort it descending, here’s the code.

   `self.carousel = function(){
        setTimeout(function() {
            //Sort random function
            owl = $('#my_carousel');
            owl.owlCarousel({
                onInitialize: function (element) {
                    owl.children().sort(function () {
                        return Math.round(Math.random()) - 0.5;
                    }).each(function () {
                        $(this).appendTo(owl);
                    });
                },
                items: 1,
                loop: true,
                nav: false,
                dots: true,
                lazyLoad: true,
                autoplay: true,
                autoplayTimeout: 4000,
                margin: 0,
                responsiveClass: true
            });
        }, 100); 
    }`

I tried to find scripts in google but it does not work or the answer is different.

2

Answers


  1. You can reverse the children before appending them

    $(owl.children().get().reverse()).each(function () {
        $(this).appendTo(owl);
    });
    
    Login or Signup to reply.
  2. You can add one more attribute called direction:
    direction:ltr,
    or
    direction:rtl,

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search