首页 > 技术文章 > 移动端遮罩及阻止页面滑动,实用!!! 我们经常做一个fixed定位的遮罩和一个提示弹框,这时就要用到。记录--

lml2017 2019-01-17 21:21 原文

1     document.body.style.height = '100%';
2     document.body.style.overflow = 'hidden';
3     document.getElementById('mark').addEventListener('touchstart',     (e) => {
4       e.stopPropagation();
5       e.preventDefault();
6     }, false);

.mark 类名的dom元素即为遮罩层的类名。

取消遮罩后,恢复滑动,只需如下:

1     document.body.style.height = 'auto';
2     document.body.style.overflow = 'auto';

 

推荐阅读