【问题标题】:Swiper Slider is not working in tabs wordpress elementorSwiper Slider 在标签 wordpress elementor 中不起作用
【发布时间】:2021-06-02 05:46:40
【问题描述】:

我正在尝试在 Elementor WordPress 的一些选项卡中加载轮播 (swiper slider)。轮播在单击选项卡之前可以正常工作,但是每当我单击选项卡时,轮播都会显示但不会“滑动”。
我很少看到有关此主题的问题并尝试了他们的解决方案,但没有运气。
现在,我正在 (child-theme/function.php) 中尝试此代码,这给了我一个错误:

错误 -> “未捕获的类型错误:无法读取未定义的属性 'params'”

add_action('wp_footer', 'swiperCarousel', 9999999999);
function swiperCarousel() {
    ?>
    <script>
var refreshSliders = function(){

        jQuery( ".swiper-container" ).each(function( index ) {
            swiperInstance = jQuery(this).data('swiper');
            swiperInstance.params.observer = true;
            swiperInstance.params.observeParents = true;
            swiperInstance.update();
        });

}

window.onload = function()
{
    console.log('Document loaded');
   
   jQuery("#aws-carousel-switcher").on("click", function(){ 
       console.log('Tab has been clicked');
            var $this = jQuery(this);
    
    refreshSliders();
    
    jQuery('html,body').animate({
                        scrollTop: $this.offset().top - 220
                    }, 500); 

        
    });
}
    </script>
    <?php
}

此行正在生成错误:

 swiperInstance.params.observer = true;

【问题讨论】:

    标签: wordpress elementor swiper.js


    【解决方案1】:

    这对你有用。

    jQuery(".swiper-container li").click(function(){
        setTimeout(function(){ window.dispatchEvent(new Event('resize')); }, 1000);
    
    })
    

    选择您各自的选项卡选择器。

    【讨论】:

    • 欢迎来到 SO。我们感谢您与该社区分享您的见解。考虑通过突出显示解决方案的重要部分并解释它如何/为什么解决 OP 的问题来提高答案的质量。如果您有文档,您还可以包含一个返回文档的链接。 SO 接受但不鼓励仅链接的答案。随着时间的推移,大多数赞成票都是从高质量的答案中积累起来的,这些答案可以帮助未来的用户学习一些东西,然后他们可以将这些东西应用到自己的编码问题、防止新问题或增加他们的一般知识库。我们期待您的更多见解。
    猜你喜欢
    • 2022-08-04
    • 1970-01-01
    • 2014-10-31
    • 2023-01-27
    • 2019-04-11
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多