Owl Carousel 2 random function

前端 未结 2 1920
刺人心
刺人心 2021-01-04 22:42

Is there a way in Owl Carousel 2 make a king random function. I need the slides on the page to load randomly.

Before in the older Owl Carousel version I did it this

2条回答
  •  一整个雨季
    2021-01-04 23:16

    You have to use the new onInitialize callback, like this:

    var owl = $('.owl-carousel');
    owl.owlCarousel({
        onInitialize : function(element){
            owl.children().sort(function(){
                return Math.round(Math.random()) - 0.5;
            }).each(function(){
                $(this).appendTo(owl);
            });
        },
    });
    

    Find more information in the 2.x docs.

提交回复
热议问题