[英]How to stop scrolling the previous page?
I am implementing a website and want to stop users go to the previous page when they scroll with two fingers on their touchpad. 我正在建立一个网站,并希望在用户用两根手指在触摸板上滚动时阻止他们转到上一页。 I tried to add scroll event and stop propagation but it doesn't work. 我试图添加滚动事件并停止传播,但是它不起作用。
document.addEventListener('scroll', (e) => {e.stopPropagation()});
document.addEventListener('touchstart', (e) => {e.stopPropagation()});
document.addEventListener('touchend', (e) => {e.stopPropagation()});
Is there any way to solve this issue? 有什么办法解决这个问题?
I have tried to disable touch-action in css but it still doesn't work: 我尝试禁用CSS中的触摸操作,但仍然无法正常工作:
touch-action: none;
I use below code to solve the issue: 我使用下面的代码来解决这个问题:
export const disableScroll = () => {
windowOnweel = window.onwheel;
window.onwheel = e => {
e = e || window.event;
if (e.preventDefault) e.preventDefault();
e.returnValue = false;
};
};
but you need to remember to restore the onwheel method when you don't need that. 但您需要记住在不需要时恢复onwheel方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.