event.stopPropagation()只能阻止事件冒泡,而swiper滑动是通过touch事件来触发的,因此无法通过阻止事件冒泡来实现阻止swiper滑动的效果。

要阻止swiper滑动,可以通过配置swiper实例的参数来实现。具体可以通过设置以下参数来实现:

  1. touchStartPreventDefault:是否阻止默认的touchstart事件,默认为true,可以设置为false来禁用阻止。

  2. touchMoveStopPropagation:是否阻止touchmove事件的冒泡,默认为false,可以设置为true来禁用冒泡。

例如:

var mySwiper = new Swiper('.swiper-container', { touchStartPreventDefault: false, touchMoveStopPropagation: true });

这样设置后,就可以禁止swiper滑动了。

eventstopPropagation;阻止swiper滑动未生效

原文地址: https://www.cveoy.top/t/topic/bAJP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录