js返回Top,弹性

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>js返回Top,弹性</title>
    <style type="text/css">
    body { height:3000px; }
    #goTopBtn { position:fixed; bottom: 35px; padding:5px; cursor: pointer; right:0; _position: absolute; _right: auto; background:#000; color:#fff; }
    </style>
</head>
<body>
    
    
   <div id="goTopBtn">Top</div>
    
    <script type="text/javascript">
    function goTopEx(){
        var obj=document.getElementById("goTopBtn");
     obj.style.display="none"; function getScrollTop(){
return document.documentElement.scrollTop; } function setScrollTop(value){ document.documentElement.scrollTop=value; } window.onscroll=function(){getScrollTop()>0?obj.style.display="":obj.style.display="none";} obj.onclick=function(){ var goTop=setInterval(scrollMove,10); function scrollMove(){ setScrollTop(getScrollTop()/1.1); if(getScrollTop()<1)clearInterval(goTop); } } } window.onload = goTopEx(); </script> </body> </html>
posted @ 2012-04-13 14:49  赵小磊  阅读(1330)  评论(0编辑  收藏  举报
回到头部