弹窗出现,禁止滑动
安卓机:
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
阻止默认事件:
e.preventDefault(); // 阻止默认事件 window.event.returnValue = false; // 阻止默认事件IE
阻止事件冒泡:
e.stopPropagation(); // 阻止冒泡 window.event.cancelBubble = true; // 阻止冒泡高版本浏览器