弹窗出现,禁止滑动

安卓机:

document.body.classList.add('no-scroll'); // 给body添加类名,no-scroll {overflow: hidden}
document.body.classList.remove('sm-no-scroll'); // 移除类名

ios和安卓机:

touchmoveHandler(e) {
        e.preventDefault();
        //alert(e.preventDefault());// undefined因为该方法没有返回值
},
document.addEventListener('touchmove', touchmoveHandler);//监听
document.removeEventListener('touchmove', touchmoveHandler);//移除

注:e.preventDefault()不兼容iPhone X

猜你喜欢

转载自www.cnblogs.com/guols/p/9430352.html
今日推荐