点击按钮,显示弹出层,将view设置为overflow:hidden, view会滚动到顶部,而不是在之前滚动条的位置,需要怎么解决?
我按下面方法设置不起作用
页面代码:
< view style = "width:100%;">
< view style = "height:3000rpx;" class = "{{ohidden?'o-hidden p-fixed':'o-empty p-static'}}">
< view > header </ view >
< view style = "margin-top:2900rpx;"> footer </ view >
< button bindtap = "button_click"> 显示弹窗 </ button >
</ view >
</ view >
< view class = "mask" wx:if = "{{showAlert}}">
< view class = "showModal">
弹窗
</ view >
</ view >
css:
.mask {
width: 100% ;
height: 100% ;
position: fixed ;
top: 0 ;
left: 0 ;
background: rgba( 0 , 0 , 0 , .7 ) ;
}
.showModal {
position: fixed ;
top: 50% ;
left: 50% ;
transform: translate( -50% , -50% ) ;
width: 70% ;
height: 600 rpx ;
background: white ;
}
.o-hidden {
overflow: hidden ;
}
.o-empty {
overflow:'';
}
.p-fixed {
position: fixed ;
}
.p-static {
position: static ;
}
js:
Page({
data: {
showAlert: false ,
ohidden: false,
scroll_top:0
},
button_click: function (){
this .setData({
showAlert: true ,
ohidden: true
})
if(wx.pageScrollTo){//滚动到滚动条位置
wx.pageScrollTo({
scrollTop: this.data.scroll_top
})
}
},
//获取滚动条当前位置
onPageScroll: function(e){
console.log(e.scrollTop);
console.log(e);
this.setData({
scroll_top: e.scrollTop
})
}
})