【发布时间】: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