如題,解決方案有兩種:
1、如果彈出層沒有滾動事件,就直接在蒙板和彈出層上加 catchtouchmove;(方便快捷)
<template name="popup-modal">
<view class="modal-overlay" catchtouchmove />
<view class="popup" catchtouchmove>
<view class="popup-title">title</view>
<view class="popup-content">content</view>
</view>
</template>
2、如果彈出層有滾動事件,有兩種方法:
方法一
在彈出層出現的時候給底部的containerView加上一個class,消失的時候移除。
<view class="{{showMask?'not-scroll':''}}">
.not-scroll{
top:0px;
left: 0px;
width: 100%;
height: 100%;
overflow: hidden;
position: fixed;
z-index: 0;
}
這種方法簡單有效,但會改變頁面原本滾動的位置(會滾動到頂部)。
方法二
給底部的containerView用<scroll-view>
包裹起來,動態設置scroll-y
,注意需要添加額外的樣式:
//somefile.wxss
.page,
page {
height: 100%;
overflow: hidden;
}
scroll-view {
height: 100%;
}
// somefile.wxml
<scroll-view
scroll-y="{{!showMask}}"
scroll-with-animation
enable-back-to-top="{{!showMask}}">
</scroll-view>
這個方法解決了方案一帶來的問題,但因為使用了<scroll-view>
標簽,又存在以下問題:
- 在 scroll-view 內有fixed定位的隱藏內容,會閃現一下,然后再隱藏的詭異bug。解決辦法是將其移動到 scroll-view 外面
- tip: 請勿在 scroll-view 中使用 textarea、map、canvas、video 組件
- tip: scroll-into-view 的優先級高於 scroll-top
- tip: 在滾動 scroll-view 時會阻止頁面回彈,所以在 scroll-view 中滾動,是無法觸發 onPullDownRefresh
- tip: 若要使用下拉刷新,請使用頁面的滾動,而不是 scroll-view ,這樣也能通過點擊頂部狀態欄回到頁面頂部
如何取舍,就看你啦~~