【问题标题】:Showing two items instead of three on initial load - WordPress/Owl Carousel在初始加载时显示两个项目而不是三个项目 - WordPress/Owl Carousel
【发布时间】:2020-08-19 10:50:44
【问题描述】:

我在 Wordpress 网站上遇到了关于 Owl Carousel 的问题。当我第一次访问该站点时,猫头鹰轮播显示两个项目,而不是脚本中添加的三个项目。问题是我没有按应有的方式显示这两个项目。如果是计划,而是第三项的 2 和 1/6: Owl carousel problem (2 items with a bit of 3rd)

当我重新加载/刷新网站时,它应该显示三个项目: Owl carousel as it should be.

我的脚本:

jQuery(document).ready(function( $ ){
    $('.owl-carousel').owlCarousel({
        loop:false,
        margin:30,
        URLhashListener:true,
        startPosition: 'URLHash',
        responsiveClass:true,
        nav:true,
        responsive:{
            0:{
                items:1,
                nav:true,
                slideBy: 1
            },
            767:{
                items:2,
                nav:true,
                slideBy: 2
            },
            1020:{
                items:3,
                nav:true,
                slideBy: 3
            }
        }
    });
}); 

您可以查看网站here 并查看底部的轮播(我正在处理该网站,因此可能会有一些变化)。

任何线索将不胜感激 - 谢谢!

【问题讨论】:

    标签: wordpress owl-carousel owl-carousel-2


    【解决方案1】:

    尝试在items: 3

    中指定默认值
    (function($) {
        $(document).ready(function() {
            $('.owl-carousel').owlCarousel({
                loop: false,
                margin: 30,
                items: 3,
                URLhashListener: true,
                startPosition: 'URLHash',
                responsiveClass: true,
                nav: true,
                responsive: {
                    0: {
                        items: 1,
                        nav: true,
                        slideBy: 1
                    },
                    767: {
                        items: 2,
                        nav: true,
                        slideBy: 2
                    }
                }
            });
        });
    })(jQuery);
    

    (离题)此外,您不应重新指定参数,例如:nav: true

    (function($) {
        $(document).ready(function() {
            $('.owl-carousel').owlCarousel({
                loop: false,
                margin: 30,
                items: 3,
                URLhashListener: true,
                startPosition: 'URLHash',
                responsiveClass: true,
                nav: true,
                responsive: {
                    0: {
                        items: 1,
                        slideBy: 1
                    },
                    767: {
                        items: 2,
                        slideBy: 2
                    }
                }
            });
        });
    })(jQuery);
    

    您可能需要等到页面完全加载后,尝试一下:

    (function ($) {
        window.addEventListener("load", function(){
            $(".owl-carousel").owlCarousel({
                loop: false,
                margin: 30,
                URLhashListener: true,
                startPosition: "URLHash",
                responsiveClass: true,
                nav: true,
                responsive: { 0: { items: 1, slideBy: 1 }, 767: { items: 2, slideBy: 2 }, 1020: { items: 3, slideBy: 3 } },
            });
        });
    })(jQuery);
    

    【讨论】:

    • 感谢您的建议,但它似乎不尊重项目中的默认值,而是采用响应项目值。第一次加载的问题仍然存在,但我可以用一个简单的 max-width 来解决它。
    • test.smagaarhus.dk 你的通话脚本在哪里?好的,我找到了
    • 你能按我说的做吗?所以我可以检查这是否不起作用? (你没有修复它)test.smagaarhus.dk/wp-content/cache/autoptimize/js/…
    • 我添加了最后一个示例
    • 我之前尝试过,但没有清除缓存,因为我是以管理员身份登录的。我已经添加了您的建议并删除了我添加的最大宽度。
    猜你喜欢
    • 2017-07-02
    • 2021-12-05
    • 1970-01-01
    • 2015-12-26
    • 2020-03-28
    • 1970-01-01
    • 2021-08-09
    • 2020-07-25
    • 1970-01-01
    相关资源
    最近更新 更多