![](/img/trans.png)
[英]In Javascript how do I stop a triggered sound after it triggers again?
[英]How do I STOP a webpage being auto scrolled again and again after it reaches to the bottom?
我是新手,正在尝试通过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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.