点选TOP后并不是直接跳到页顶的,而是滚动上去

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>runcode</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="Sheneyan" />
<script>
function s2top(){
var a = document.getElementsByTagName('a');
var l = a.length;
for (var i = 0 ; i < l ; i ++){
  var ai = a[i];
  if (/#header$/.test(ai.href)){
    ai.onclick = function(){
      var o = this;
      var ot = o.offsetTop;
      for (var t = 0 ; t < 20 ; t ++){
        setTimeout("scrollBy(0,-" + parseInt(ot / 20) + ")",t * 50 + 1);
      }
      return false;
    }
  }
}
}
</script>
<body οnlοad="s2top()">
</body>
<p>
<script>
for (var i = 0 ; i < 1000 ; i ++)
  document.write(i+"<br>");
</script>
</p>
<a href="#header">go to 头</a>
</body>demo中的p中的script改大或改小看看。。。移动到top的时间始终是一定的,你也可以设置一个阀值,在页面高度到达这个阀值之前,移动的总时间是多少,当页面高度超过这个数时,移动的总时间反而以一定比例减小,自己试试看吧... http://www.corange.cn/archives/2008/05/1107.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值