猫头鹰传送带2随机功能 [英] Owl Carousel 2 random function

查看:74
本文介绍了猫头鹰传送带2随机功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Owl Carousel 2中有一种方法可以使国王具有随机功能.我需要页面上的幻灯片随机加载.

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

在较旧的Owl Carousel版本中,我是这样进行的:

Before in the older Owl Carousel version I did it this way:

$(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中以最佳方式完成此操作?

How can this be done in the best way in Owl Carousel 2?

推荐答案

您必须使用新的onInitialize回调,如下所示:

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);
        });
    },
});

2.x文档中查找更多信息..

Find more information in the 2.x docs.

这篇关于猫头鹰传送带2随机功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆