Javascript 如何停止滚动上一页?
我正在实现一个网站,希望阻止用户在触摸板上用两个手指滚动时转到上一页。我试图添加scroll事件并停止传播,但它不起作用Javascript 如何停止滚动上一页?,javascript,jquery,Javascript,Jquery,我正在实现一个网站,希望阻止用户在触摸板上用两个手指滚动时转到上一页。我试图添加scroll事件并停止传播,但它不起作用 document.addEventListener('scroll', (e) => {e.stopPropagation()}); document.addEventListener('touchstart', (e) => {e.stopPropagation()}); document.addEventListener('touchend', (e) =&g
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
事件。浏览器检测来自两个手指的事件,将它们编译在一起并确定行为。