javascript - Owl Carousel 2随机功能

标签 javascript jquery carousel owl-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);
        }
    });
});

如何在 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/

相关文章:

css - 下拉菜单不适用于图像轮播

javascript - 如何在jquery中单击时将轮播元素移动到中间

javascript - 发现了意外的 token ,但没有看到它

javascript - 退出 firebase 身份验证

javascript - 如何在 Javascript 中使用 Laravel URL::to?

javascript - 通过javascript从IE中的JSON导出CSV

html - 我可以将 Bootstrap Carousel 移到右侧而不是中心吗?

Javascript `?.` 运算符 : why is `not defined` not treated as `undefined` ?

javascript - ngx-quill/quill.js 从innerHTML中去除自定义印迹

jquery - 重构 navBar jQuery 代码