如何在鼠标滚轮移动时停止自动滚动功能

How can I stop an automatic scrolling function whenever the mouse wheel moves?

本文关键字:功能 滚动 移动 鼠标      更新时间:2023-09-26

我有一个网站,页面自动缓慢滚动通过这个脚本:

function jumpScroll() {
    window.scrollBy(0,1);
    scrolldelay = setTimeout('jumpScroll()',10);
}

每当有人移动鼠标滚轮时,我希望自动滚动停止。

任何建议都是受欢迎的。

假设滚动延迟是上下文中的全局变量,则可以调用clearTimeout

clearTimeout(scrolldelay);

这将导致超时不再触发。

你只需要把它放在捕捉鼠标滚轮事件的地方。