阻止页面滚动的方法
//阻止浏览器事件
function disabledMouseWheel() {
document.addEventListener('DOMMouseScroll', scrollFunc, {
passive: false
});
document.addEventListener('mousewheel', scrollFunc, {
passive: false
});
}
//取消阻止浏览器事件
function cancelDisMouseWheel() {
document.removeEventListener('DOMMouseScroll', scrollFunc, {
passive: false
});
document.removeEventListener('mousewheel', scrollFunc, {
passive: false
});
}
function scrollFunc(evt) {
evt = evt || window.event;
if (evt.preventDefault) {
// Firefox
evt.preventDefault();
evt.stopPropagation();
} else {
// IE
evt.cancelBubble = true;
evt.returnValue = false;
}
return false;
}