效果应用于 返回顶部按钮、左右对联广告
display函数用于控制距离顶部多远,按钮出现
<script> lastScrollY=0; function heartBeat(){ var diffY; if (document.documentElement && document.documentElement.scrollTop) diffY = document.documentElement.scrollTop; else if (document.body) diffY = document.body.scrollTop else {/*Netscape stuff*/} percent=.1*(diffY-lastScrollY); if(percent>0)percent=Math.ceil(percent); else percent=Math.floor(percent); document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px"; lastScrollY=lastScrollY+percent; } suspendcode="<div id=\"goback\"><div id=\"full\" style='POSITION:absolute;TOP:300px;z-index:100; cursor:pointer;'><img onclick='window.scrollTo(0,0);' src=\"style/images/goback.gif\"></div></div>" document.write(suspendcode); window.setInterval("heartBeat()",1); function display(){ var b_top= document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;; if(b_top>200) document.getElementById("goback").style.display = "block"; else document.getElementById("goback").style.display = "none"; setTimeout("display();",100); } display(); </script>