这里是不是有个bug!
在一屏之下刷新页面,浏览器记录之前的位置 按道理这时候按钮是显示的 但是你设置display默认为none 这时候没有scroll事件,所以按钮会不显示,这不是个问题吗?
在一屏之下刷新页面,浏览器记录之前的位置 按道理这时候按钮是显示的 但是你设置display默认为none 这时候没有scroll事件,所以按钮会不显示,这不是个问题吗?
2017-03-18
感觉是的,这视频分享不错,但是有一些小bug,这也算是个问题吧,我觉得可以在window.onload 之后,可以先判断(scrollHeight >= clientHeight),就可以解决这问题了
window.onload = function(){
var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
var obtn=document.getElementById("btn");
scrollHeight = document.documentElement.scrollTop || document.body.scrollTop;
if(scrollHeight >= clientHeight){
obtn.style.display = "block";
} else{
obtn.style.display = "none";
}
没有看到你说的bug,
window.onload = function(){
var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
var obtn=document.getElementById("btn");
var timer=null;
var scrollHeight;
window.onscroll=function(){
scrollHeight = document.documentElement.scrollTop || document.body.scrollTop;
if(scrollHeight >= clientHeight){
obtn.style.display = "block";
}
else{
obtn.style.display = "none";
}
}
obtn.onclick=function(){
timer=setInterval(function(){
//var scrollHeight = document.documentElement.scrollTop || document.body.scrollTop;
var speed = Math.ceil(scrollHeight / 6);
document.documentElement.scrollTop = document.body.scrollTop =scrollHeight - speed;
//console.log(scrollHeight - speed);
if(scrollHeight == 0){
clearInterval(timer);
}
},30);
}
}
举报