[英]How do I STOP a webpage being auto scrolled again and again after it reaches to the bottom?
I am a newbie and trying to implement a JS code via Greasemonky that auto scrolls till the very bottom of the page. 我是新手,正在尝试通过Greasemonky实现JS代码,该代码会自动滚动到页面的最底部。 But if I scroll up, it keeps scrolling again so I want it to stop scrolling once I click a stop button.
但是,如果我向上滚动,它将继续滚动,因此,当我单击停止按钮时,我希望它停止滚动。
// 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();
}
First, declare variable interval 首先,声明可变间隔
var interval = setInterval(function(s){scrollBy(0,s||10000)},1000);
and then clean it in function 然后在功能上清理它
function stopScroll()
{
clearInterval(interval);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.