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

为什么这个 ”点击回到顶部按钮后 滑动滑轮的效果“ 在 IE可以 在chrom 里不行

window.onload = function(){

var hiee = document.documentElement.clientHeight;

var timer=null;

var btn = document.getElementById("btn");

var isT = true;

window.onscroll = function(){

var ttop = document.documentElement.scrollTop || document.body.scrollTop;

if(ttop >= hiee){

btn.style.display= "block";

}else{

btn.style.display= "none";

}

if(!isT){

clearInterval(timer);

}

isT = false;

}

btn.onclick = function(){

timer = setInterval(function(){

var ttop = document.documentElement.scrollTop||document.body.scrollTop;

var ispeed = Math.floor(-ttop / 6);

document.documentElement.scrollTop = document.body.scrollTop = ispeed +ttop;

//document.documentElement.scrollTop = document.body.scrollTop = ttop - ttop/50;

// = function(){clearInterval(timer)}

isT = true;

if( ttop == 0){

clearInterval(timer)

}

},10)

}

}


正在回答

3 回答

http://img1.sycdn.imooc.com//5684f89d0001898f05680063.jpg

看看是不是没有空格的原因

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

是不是有浏览器兼容问题

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

qq_e累_0 提问者

对 有
2015-11-28 回复 有任何疑惑可以回复我~
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
 #btn {
 width:40px;
 height:40px;
 position:fixed;
 left:50%;
 display:none;
 margin-left:610px;
 bottom:30px;
 background:url(http://img1.sycdn.imooc.com//535e0dc100010e9c00400080.jpg) no-repeat left top;
        }
 #btn:hover {
 background:url(http://img1.sycdn.imooc.com//535e0dc100010e9c00400080.jpg) no-repeat 0 -39px;
        }
        .box {
 width:1190px;
 margin:0 auto;
        }
 </style>
</head>
<body>
<div class="box">
    <img src="http://img1.sycdn.imooc.com//535e0ce800015b7511902787.jpg"/>
</div>
<a href="javascript:;" id="btn" title="回到顶部"></a>
<script>
 window.onload = function () {
 var hiee = document.documentElement.clientHeight;
 var timer = null;
 var btn = document.getElementById("btn");
 var isT = true;
 window.onscroll = function () {
 var ttop = document.documentElement.scrollTop || document.body.scrollTop;
 if (ttop >= hiee) {
 btn.style.display = "block";
            } else {
 btn.style.display = "none";
            }
 if (!isT) {
 clearInterval(timer);
            }
 isT = false;
        }
 btn.onclick = function () {
 timer = setInterval(function () {
 var ttop = document.documentElement.scrollTop || document.body.scrollTop;
 var ispeed = Math.floor(-ttop / 6);
 document.documentElement.scrollTop = document.body.scrollTop = ispeed + ttop;
//document.documentElement.scrollTop = document.body.scrollTop = ttop - ttop/50;
// = function(){clearInterval(timer)}
 isT = true;
 if (ttop == 0) {
 clearInterval(timer)
                }
            }, 10)
        }
    }
</script>
</body>
</html>

谷歌里可以的

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

qq_e累_0 提问者

chrom里不可以 就是 滚动条自动向上滑时 滑动鼠标滑轮 没有清除定时器 同学的代码 在chrom也可以
2015-11-27 回复 有任何疑惑可以回复我~

举报

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

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

进入课程

为什么这个 ”点击回到顶部按钮后 滑动滑轮的效果“ 在 IE可以 在chrom 里不行

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信