javascript disable scroll event
javascript disable scroll event
Document: scroll event
https://developer.mozilla.org/en-US/docs/Web/API/Document/scroll_event
https://developer.mozilla.org/en-US/docs/Web/API/Element/scroll_event
stopScrollEvent = (e) => {
// log(`stop 滚动穿透`, e);
e.preventDefault();
e.stopPropagation();
// e.stopPropagation();
// e.preventDefault();
this.handleTouchScroll();
return;
}
handleTouchScroll = (flag = `true`) => {
log(`touch scroll`)
// if (ENV !== Taro.ENV_TYPE.WEB) {
// return
// }
document.body.addEventListener(`scroll`, (e) => {
e.preventDefault();
e.stopPropagation();
return;
log(`no scroll event`)
});
let scrollTop = 0;
if (flag) {
scrollTop = document.documentElement.scrollTop
// 使body脱离文档流
document.body.classList.add('at-frozen')
// 把脱离文档流的body拉上去!否则页面会回到顶部!
document.body.style.top = `${-scrollTop}px`
} else {
document.body.style.top = null
document.body.classList.remove('at-frozen')
document.documentElement.scrollTop = scrollTop
}
}
https://javascript.info/onscroll
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/12616962.html
未经授权禁止转载,违者必究!