del*_*mar 8 javascript jquery carousel 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);
}
});
});
Run Code Online (Sandbox Code Playgroud)
如何在Owl Carousel 2中以最佳方式完成此操作?
Adm*_*eNL 17
你必须使用新的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);
});
},
});
Run Code Online (Sandbox Code Playgroud)
在2.x文档中查找更多信息.
| 归档时间: |
|
| 查看次数: |
5792 次 |
| 最近记录: |