<!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>