<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script type="text/javascript">
window.onload=function(){
var btn=document.getElementById("returntop");
var timer=null;
btn.onclick=function(){
timer=setInterval(function(){
if (scroll_top==0) { clearInterval(timer)}
var scroll_top=document.documentElement.scrollTop||document.body.scrollTop;
//变速回到顶部
var speed=scroll_top/8;
document.documentElement.scrollTop=document.body.scrollTop=(scroll_top-speed);
console.log(scroll_top+" "+speed);
},20);
}
}
</script>
</head>
<bodyx>
<div style="height: 4000px;"></div>
<input type="button" value="回到顶部" id="returntop">
</body>
</html>