为了账号安全,请及时绑定邮箱和手机立即绑定

这里是不是有个bug!

在一屏之下刷新页面,浏览器记录之前的位置  按道理这时候按钮是显示的  但是你设置display默认为none  这时候没有scroll事件,所以按钮会不显示,这不是个问题吗?

正在回答

2 回答

感觉是的,这视频分享不错,但是有一些小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";    

        }

        

0 回复 有任何疑惑可以回复我~

没有看到你说的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);

}

}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
回到顶部效果
  • 参与学习       44208    人
  • 解答问题       206    个

回到顶部网站不可缺少的一部分,用JS实现炫酷拉风的回到顶部效果

进入课程

这里是不是有个bug!

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号