美文网首页
小程序 自定义弹窗后禁止屏幕滚动(滚动穿透)

小程序 自定义弹窗后禁止屏幕滚动(滚动穿透)

作者: 下班再说 | 来源:发表于2021-03-25 09:38 被阅读0次

弹出 fixed 弹窗后,在弹窗上滑动会导致下层的页面一起跟着滚动。

解决方法:

在弹出层加上 catchtouchmove 事件

示例代码:

<view class="modal-view" hidden="{{!showModal}}" bindtap="toggleModal" catchtouchmove="preventTouchMove">

  <view class="modal">

  <view class="modal-item" catchtap="makePhoneCall">{{site.phone}}</view>

  <view class="modal-item" catchtap="toggleModal">取消</view>

  </view>

</view>

Pages({

  preventTouchMove() {}

})

  在电脑上测试是没有用的,这是触摸事件。因此,需要在手机端测试,预览生成一个开发版,用手机微信扫描即可看到效果。

还有一种方法如下:给catchtouchmove="ture"(我选第二种)

<view class="modal-view" hidden="{{!showModal}}" bindtap="toggleModal" catchtouchmove="ture">

  <view class="modal">

  <view class="modal-item" catchtap="makePhoneCall">{{site.phone}}</view>

  <view class="modal-item" catchtap="toggleModal">取消</view>

  </view>

</view>

相关文章

网友评论

      本文标题:小程序 自定义弹窗后禁止屏幕滚动(滚动穿透)

      本文链接:https://www.haomeiwen.com/subject/ehrlhltx.html