为什么在onclick函数里加了isTop = true;就可以了?这个逻辑不太理的通,求帮助
window.onload = function(){
var obtn = document.getElementById("btn");
var clientHeight = document.documentElement.clientHeight || document.body.clientHeight; //获取屏幕高度
var timer = null;
var isTop = true;
//滚动条滚动时触发
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(){
//设置定时器
clearInterval(timer);
timer = setInterval(function(){
//滚动条距离顶部的距离
var osTop = document.documentElement.scrollTop || document.body.scrollTop;
var ispeed = Math.floor(-osTop / 30);
document.documentElement.scrollTop = document.body.scrollTop = osTop + ispeed;
isTop = true;
if(osTop == 0){
clearInterval(timer);
}
},30);
}
}