欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

js动态移动滚动条至底部示例代码_javascript技巧

程序员文章站 2022-03-19 18:10:37
...
复制代码 代码如下:

var currentPosition,timer;
function GoBottom(){
timer=setInterval("runToBottom()",50);
}
function runToBottom(){
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition+=30;
if(currentPosition{
//window.scrollTo(0,currentPosition);
//alert(document.documentElement.clientHeight + " " + document.documentElement.scrollTop + " " + document.documentElement.scrollHeight + "#" +document.body.clientHeight + " " + document.body.scrollTop + " " + document.body.scrollHeight);
document.body.scrollTop = currentPosition;
}
else
{
document.body.scrollTop = document.body.scrollHeight;
clearInterval(timer);
}
}