移动端遮罩及阻止页面滑动,实用!!! 我们经常做一个fixed定位的遮罩和一个提示弹框,这时就要用到。记录--
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';
本文来自博客园,作者:秋风2016,转载请注明原文链接:https://www.cnblogs.com/lml2017/p/10284624.html