小程序顯示彈窗時禁止下層的內容滾動實現方法,具體如下
① 第一種方式
利用position:fixed. 禁止頁面滾動.
一. 頁面結構html
<view class="indexPage {{proInfoWindow?'indexFixed':''}}"> -----------此處為整個頁面的結構內容 <button catchTap="_proInfoWindowShow">點擊顯示彈窗</button></view>// 當proInfoWindow為true的時候顯示彈窗<view wx:if="{{proInfoWindow}}">此處為彈窗內容</view>
二. CSS部分
//添加一個類名, 把彈窗的下層內容定位為fixed.實現禁止滾動的效果.indexFixed{ position: fixed; top:0;//top:0可不寫,否則顯示彈窗的同時會使底層滾動到頂部. left:0; bottom:0; right:0;}
三. JS部分
Page({ data: { proInfoWindow:false,//控制彈窗是否顯示 }, // 點擊彈窗事件, 設置proInfoWindow為true, 顯示彈窗. // 設置proInfoWindow為true的同時, 給頁面添加了一個class名為indexFixed的類.顯示彈窗時下層就禁止滾動,關掉彈窗時就可以滾動. _proInfoWindowShow(){ this.setData({ proInfoWindow:true }) }})
②第二種方式
用 catchtouchmove="return"
//此處為彈窗內容<view catchtouchmove="return"> //外層加 catchtouchmove="return"僅觸摸背景區域時不穿透底部. <view catchtouchmove="return"></view> //在每個小的區域內加 catchtouchmove="return" <view> // 有需要滾動的列表區域位置不要加 catchtouchmove="return", 否則列表無法滾動 <view>滾動列表1</view> <view>滾動列表2</view> <view>滾動列表3</view> <view>滾動列表4</view> </view></view>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答