分享javascript动态移动滚动条至底部的例子

分类:Javascript| 发布:佚名| 查看: | 发表时间:2014/6/9
页面太长了,鼠标滚动到页面底部很是费劲,我们知道,可以通过点击一个锚点到底部,这种效果不是很好,怎么实现动态滚动到底部呢?
代码如下:

var currentPosition,timer;
function GoBottom(){
    timer=setInterval("runToBottom()",50);
}
function runToBottom(){
    currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
    currentPosition+=30;
    if(currentPosition<document.body.scrollHeight && (document.body.clientHeight + document.body.scrollTop < document.body.scrollHeight))
   {
         //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);
   }
}
365据说看到好文章不转的人,服务器容易宕机
原创文章如转载,请注明:转载自郑州网建-前端开发 http://camnpr.com/
本文链接:http://camnpr.com/javascript/1182.html