vue移动端弹起蒙层滑动禁止底部滑动操作
时间:2022-01-20 09:17:22|栏目:vue|点击: 次
解决办法
在蒙层弹起的时候将body设置为fixed定位
在蒙层消失的时候将body恢复原位
popupVisible(newValue) {
if (newValue) {
document.body.style.position = 'fixed';
document.body.style.width = '100%';
document.body.style.height = '100%';
}
else {
document.body.style.position = 'static';
document.body.style.height = 'auto';
}
},
设置为fixed的时候整个页面会恢复原位,如果需要把位置开始scrollY记下来,恢复的时候在滚到原来的位置
popupVisible(newValue) {
if (newValue) {
document.body.style.position = 'fixed';
document.body.style.width = '100%';
document.body.style.height = '100%';
this.top = window.scrollY;
}
else {
document.body.style.position = 'static';
document.body.style.height = 'auto';
window.scrollTo(0, this.top);
}
}
补充知识:解决使用vue时页面内有弹窗时禁止页面滚动 以及页面内弹窗因绝对定位导致页面压缩的问题
如下所示:
@touchmove.prevent
当页面弹窗出现时设置 @touchmove.prevent = "false";
2.页面内弹窗因绝对定位导致页面压缩的问题 造成底部导航栏固定在输入键盘上面的问题
// 动态设置背景图的高度为浏览器可视区域高度
// 首先在Virtual DOM渲染数据时,设置下背景图的高度.
this.bodyHeight = `${document.documentElement.clientHeight}`;
// 然后监听window的resize事件.在浏览器窗口变化时再设置下背景图高度.
window.onresize = function temp() {
var bodyHeight = `${document.documentElement.clientHeight}`;
that.bodyHeight = bodyHeight;
};
通过判断 bodyHeight 数值的变化,来控制底部导航栏的出现与隐藏
上一篇:vue通过video.js解决m3u8视频播放格式的方法
栏 目:vue
下一篇:Vue 动态路由的实现及 Springsecurity 按钮级别的权限控制
本文标题:vue移动端弹起蒙层滑动禁止底部滑动操作
本文地址:http://www.codeinn.net/misctech/190778.html






