我的.scrollBottom按钮有效,但是一旦它自动滚动到底部我无法手动向上滚动,因为它处于活动状态且不断向下滚动。它需要什么才能滚动到绝对底部然后停止?
的JavaScript
var timeOut;
function scrollToBottom() {
if (document.body.scrollBottom!=0 || document.documentElement.scrollBottom!=0){
window.scrollBy(0,20);
timeOut=setTimeout('scrollToBottom()',10);
}
else clearTimeout(timeOut);
}
HTML
<a href="#" onclick="scrollToBottom();return false">BUTTON</a>
答案 0 :(得分:0)
我发现通过删除timeOut=setTimeout('scrollToBottom()',10);
按下时按钮向下滚动20个像素。
有了这些信息,我将window.scrollBy(0,20);
更改为一个荒谬的数字,例如:window.scrollBy(0,2000000);
所以我得到了这段代码:
var timeOut;
function scrollToBottom() {
document.body.scrollBottom!=0 || document.documentElement.scrollBottom!=0
window.scrollBy(0,2000000);
}
并与
配对html {
scroll-behavior: smooth;
}
它可以解决问题:)