1 回答

TA贡献1770条经验 获得超3个赞
看来我可能已经解决了这个问题。似乎即使您全局声明了 swiper,swiper.js 也无法访问它,因为一些奇怪的原因,所以我找到了一个解决方法。也许这是设计它的方式,但至少对我来说,它没有什么意义。
首先,您需要在一个函数中声明您的刷卡器,如下所示:
function carouselProperties() {
return new Swiper(".swiper-container", {
init: false,
freeMode: true,
slidesPerView: "auto",
});
}
之后我们进入应该调用滑动器的函数内部,在本例中是点击事件监听器。
$(".card").click(function(){
// Here we define a variable that returns the swiper
const carousel = carouselProperties()
// Afte we define this variable we can finally call the init function
carousel.init();
});
回顾一下:
您定义一个返回滑动器及其属性的函数。
您在所有其他需要检索刷卡信息的函数中调用该函数。
我希望这能帮助任何和我有同样问题的人。
添加回答
举报