87,838
社区成员




<html>
<head>
<style>
#btn1 {position:fixed; bottom:0; right:0;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function ()
{
var oBtn=document.getElementById('btn1');
var bSys=true;//这一步为什么要这样写??
var timer=null;
//如何检测用户拖动了滚动条
window.onscroll=function ()
{
if(!bSys) //还有这一步,系统怎么知道是false啊
{
clearInterval(timer);
}
bSys=false;
//alert("a")
};
oBtn.onclick=function ()
{
timer=setInterval(function (){
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
var iSpeed=Math.floor(-scrollTop/8);
if(scrollTop==0)
{
clearInterval(timer);
}
bSys=true;
document.documentElement.scrollTop=document.body.scrollTop=scrollTop+iSpeed;
}, 30);
};
};
</script>
</head>
<body>
1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />
<input id="btn1" type="button" value="回到顶部" />
</body>
</html>