小程式彈窗禁止頁面滾動
阿新 • • 發佈:2018-12-25
彈出 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>