日期:2014-05-16 浏览次数:20309 次
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>scroll事件监听</title> <script type="text/javascript"> function gotop() { var y= document.documentElement?(document.documentElement.scrollTop || 0):(document.body.scrollTop || 0); y = Math.max(y, (window.scrollY || 0)); var o=document.getElementById("gotop"); if(y>677) { var left=document.body.clientWidth-parseInt(o.style.width)-10; var top=document.body.offsetHeight-parseInt(y)/2-10; o.style.left=left+'px'; o.style.top=top+'px'; o.style.display='block'; }else{o.style.display='none';} } window.attachEvent?window.attachEvent("onscroll",gotop):window.addEventListener("scroll",gotop,false); </script> </head> <body> <div style="height:677px;border:1px solid #bfbfbf;"></div> <div style="height:677px;border:1px solid #bfbfbf;"></div> <div id="gotop" style=" position:absolute; display:none;width:65px;height:25px;line-height:25px;"><a href="javascript:window.scrollTo(0,0);">回到顶部</a></div> </body> </html>