只有一张图片时,猫头鹰轮播不显示

时间:2017-04-13 09:01:09

标签: jquery owl-carousel

我正在使用owl carousel并拥有以下代码

// Home Slider    
    $("#home-slider").owlCarousel({
        loop: true,
        items: 1,
        dots: false,
        nav: true,
        autoplayTimeout: 4500,
        smartSpeed: 2000,
        autoHeight: false,
        touchDrag: true,
        mouseDrag: true,
        margin: 0,
        autoplay: true,
        slideSpeed: 600,
        navText: ['<i class="fa fa-angle-left" aria-hidden="true"></i>', '<i class="fa fa-angle-right" aria-hidden="true"></i>'],

似乎工作正常,直到旋转木马上只有一张幻灯片。阅读例如owl carousel 2 not work with loop and 1 items (Bug Fixed Now)建议在循环选项

上使用以下内容
loop: ($(".owl-carousel .owl-item").length >= 1) ? true : false;

但是,当运行此代码时,它总是计算为false,因此虽然它显示一个图像,但是当有多个图像时它会中断循环。凭借我有限的JQuery知识,我已经将一些日志记录到控制台中,我认为正在发生的是循环:($(“。owl-carousel .owl-item”)。length&gt; = 1)?真假;在加载DOM之前正在评估代码,并且无法找到owl正在添加的类。当我签入开发人员工具时(当DOM加载时)我看到了我期望的结果......($(“。owl-carousel .owl-item”)。length&gt; = 1)评估为True

这种分析可能有误,但是有人对我如何才能使这个工作有任何建议吗?

由于 保罗

1 个答案:

答案 0 :(得分:0)

您需要将singleItem设置为true才能使其正常运行。

相关问题