Owl Carousel 2 random function

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

Earlier in the old version of an owl carousel, I did it like this:

$(document).ready(function () { //Sort random function function random(owlSelector) { owlSelector.children().sort(function () { return Math.round(Math.random()) - 0.5; }).each(function () { $(this).appendTo(owlSelector); }); } $(".feedback").owlCarousel({ autoPlay: 5000, slideSpeed: 200, items: 1, itemsDesktop: [1199, 1], itemsDesktopSmall: [979, 1], itemsTablet: [768, 1], itemsMobile: [479, 1], autoHeight: true, //Call beforeInit callback, elem parameter point to $(".feedback") beforeInit: function (elem) { random(elem); } }); }); 

How can this be best done in Owl Carousel 2?

+5
source share
1 answer

You should use the new onInitialize , for example:

 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 2.x docs .

+13
source

Source: https://habr.com/ru/post/1212454/


All Articles