改了一些代码,但是效果出不来,clientHeight测出来的效果是2803,求各位大神看看哪里出错
window.onload=function(){
var obtn=document.getElementById('btn');
var timer=null;
var isTop=true;
var clientHeight=document.documentElement.clientHeight || document.body.clientHeight;
window.onscroll=function(){
var osTop=document.documentElement.scrollTop || document.body.scrollTop;
if(osTop>=clientHeight){
obtn.style.display="block";
}else{
obtn.style.display="none";
}
if(!isTop){
clearInterval(timer);
}
isTop=false;
}
obtn.onclick=function(){
timer=setInterval(function(){
var osTop=document.documentElement.scrollTop || document.body.scrollTop;
var ispeed=Math.ceil(osTop/5);
document.documentElement.scrollTop=document.body.scrollTop=osTop-ispeed;
if(osTop==0){
clearInterval(timer);
}
isTop=true;
},40)
}
}