微信小程序中 swiper 组件可以通过控制 catchtouchmove 函数来禁止上下滑动,但是通过这种方法禁止 swiper 组件滑动后,整个页面也无法滑动了。

<swiper class="myswiper">
    <swiper-item catchtouchmove="stopTouchMove"><swiper-item></swiper-item>
</swiper>
stopTouchMove: function () {
    return false;
}

解决办法:

<swiper class="myswiper">
    <swiper-item catchtouchmove="stopTouchMove"><swiper-item></swiper-item>
</swiper>
.myswiper {
    position: relative;
}
.myswiper::after {
    position: absolute;
    content: '';
    top: 0;
    left: 0;
    width: 100%;
}
(adsbygoogle = window.adsbygoogle || []).push({});