如何阻止网页在到达底部后一次又一次地自动滚动

How do I STOP a webpage being auto scrolled again and again after it reaches to the bottom?

本文关键字:一次又一次 滚动 底部 网页 何阻止      更新时间:2023-09-26

我是新手,并尝试通过Greasemonky实现JS代码,该代码会自动滚动到页面的最底部。但是如果我向上滚动,它会再次滚动,所以我希望它在我单击停止按钮后停止滚动。

// Scrolls till the bottom
setInterval(function(s){scrollBy(0,s||10000)},1000);

//script that creates a button
var input = document.createElement('input');
input.type = 'button';
input.value = 'Stop scrolling';
input.onclick = stopScroll; 
document.body.appendChild(input);
//I need help here, not sure how to use clearInterval.
function stopScroll()
{
  clearInterval();      
}

首先,声明变量间隔

var interval = setInterval(function(s){scrollBy(0,s||10000)},1000);

然后在功能中清理它

function stopScroll()
{
clearInterval(interval);      
}