当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 点选TOP后并不是直接跳到页顶的,而是滚动上去的

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 194 ::
收藏到网摘: n/a

如果网页太长了,一般都使用锚标签快速返回到TOP
<a href="#header" title="back to top">top</a> 确实很简单,不过却有一些高手让这个简变成不简单:
国外演示地址:http://tonyyoo.com/v2/
点选TOP后并不是直接跳到页顶的,而是滚动上去的。。而且距离页顶越长滚动的速度也就越快。。。
研究了下,用到的JS有4个:
<script type="text/javascript" src="scripts/prototype.lite.js"></script>
<script type="text/javascript" src="scripts/moo.fx.js"></script>
<script type="text/javascript" src="scripts/moo.fx.pack.js"></script>
<script type="text/javascript" src="scripts/pageScroll.js"></script>
看起来都好复杂。。不知道有没有可以精简点的代码可以实现同样的效果呢,我是做不来的了。。
在页面onload之后,遍历所有超链接,判断href中是否有#header,有的话触发scrollTo即可。。。
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]