Owl Carousel 2 中有没有办法制作国王随机功能。我需要页面上的幻灯片随机加载。
在旧的 Owl Carousel 版本中,我是这样做的:
$(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);
}
});
});
如何在 Owl Carousel 2 中以最佳方式做到这一点?
最佳答案
您必须使用新的 onInitialize
回调,如下所示:
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);
});
},
});
在 2.x docs 中查找更多信息.
关于javascript - Owl Carousel 2随机功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28283603/