[英]How to stop scrolling the previous page?
我正在建立一個網站,並希望在用戶用兩根手指在觸摸板上滾動時阻止他們轉到上一頁。 我試圖添加滾動事件並停止傳播,但是它不起作用。
document.addEventListener('scroll', (e) => {e.stopPropagation()});
document.addEventListener('touchstart', (e) => {e.stopPropagation()});
document.addEventListener('touchend', (e) => {e.stopPropagation()});
有什么辦法解決這個問題?
我嘗試禁用CSS中的觸摸操作,但仍然無法正常工作:
touch-action: none;
我使用下面的代碼來解決這個問題:
export const disableScroll = () => {
windowOnweel = window.onwheel;
window.onwheel = e => {
e = e || window.event;
if (e.preventDefault) e.preventDefault();
e.returnValue = false;
};
};
但您需要記住在不需要時恢復onwheel方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.