你的位置: Kiyo'Space首页 JavaScript/Jscript 阅读文章 欢迎留下您的足迹

快捷控制滚动条到页面顶部TOP

[ JavaScript/Jscript ] 分享

如果页面太长,通过此方法可能做个连接的东西实现.

<style type="text/css">
<!--
#floater {position:absolute; visibility:visible}
-->
</style>
<script language="JavaScript">
<!--
 self.onError=null;
 currentX = currentY = 0; 
 whichIt = null;          
 lastScrollX = 0; lastScrollY = 0;
 NS = (document.layers) ? 1 : 0;
 IE = (document.all) ? 1: 0;
 <!-- STALKER CODE -->
 function heartBeat() {
  if(IE) {
     diffY = document.body.scrollTop;
      diffX = 0;
         }
     if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
  if(diffY != lastScrollY) {
                 percent = .1 * (diffY - lastScrollY);
                 if(percent > 0) percent = Math.ceil(percent);
                 else percent = Math.floor(percent);
   if(IE) document.all.floater.style.pixelTop += percent;
   if(NS) document.floater.top += percent;
                 lastScrollY = lastScrollY + percent;
     }
  if(diffX != lastScrollX) {
   percent = .1 * (diffX - lastScrollX);
   if(percent > 0) percent = Math.ceil(percent);
   else percent = Math.floor(percent);
   if(IE) document.all.floater.style.pixelLeft += percent;
   if(NS) document.floater.top += percent;
   lastScrollY = lastScrollY + percent;
  } 
 } 
 if(NS || IE) action = window.setInterval("heartBeat()",1);
//-->
</script>

<!--top Start-->
<div id="floater" style="position:absolute; left:755px; top:320px; width:26px; height:24px; z-index:0">
 <A onfocus=this.blur(); href="#top"><img src="/img/top.gif" border=0></a>
</div>
<!--top End-->


欢迎在此留下您的脚步






评论内容 (*必填):
(Ctrl + Enter 快速提交)