Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何停止滚动上一页?_Javascript_Jquery - Fatal编程技术网

Javascript 如何停止滚动上一页?

Javascript 如何停止滚动上一页?,javascript,jquery,Javascript,Jquery,我正在实现一个网站,希望阻止用户在触摸板上用两个手指滚动时转到上一页。我试图添加scroll事件并停止传播,但它不起作用 document.addEventListener('scroll', (e) => {e.stopPropagation()}); document.addEventListener('touchstart', (e) => {e.stopPropagation()}); document.addEventListener('touchend', (e) =&g

我正在实现一个网站,希望阻止用户在触摸板上用两个手指滚动时转到上一页。我试图添加scroll事件并停止传播,但它不起作用

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方法。

的可能重复简言之,触摸滚动不会触发
scroll
事件。它会触发
touchstart
touchend
事件。浏览器检测来自两个手指的事件,将它们编译在一起并确定行为。