回到頂部,哪兒出錯(cuò)了???
window.onload=function(){
var Back=document.getElementById("top");
var timer=null;
var Top=true;
window.onscroll=function(){
if(!Top){
clearInterval(timer);
}s
Top=false;
};
Back.onclick=function(){
timer=setInterval(function(){
var Top=document.documentElement.scrollTop||document.body.scrollTop;
var Speed=Math.floor(-Top/3);
document.documentElement.scrollTop=document.body.scrollTop=Top+Speed;
Top=true;
if(Top==0){
clearInterval(timer);
}
},30);
}
};
不知道哪里錯(cuò)了,在瀏覽器預(yù)覽時(shí)候,不能回到頂部,點(diǎn)擊一次,滾動(dòng)條只移動(dòng)一小段距離
2015-04-20
Top變量定義重了,建議換個(gè)名字