Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

如何解决overflow: hidden后滚动条不被监听

事情是这样的:
html和body给了样式:

html,body{
      height: 100%;
      overflow: hidden;
    }

里面的容器给了样式:

#app{
      height: 100%;
      overflow: auto;
    }

结构是这样的:

<body>
  <div id="app"></div>
  <a class="tips" href="javascript:scroll(0,0)" id="tips">回到顶部</a>
</body>       

问题出现了,之前设置的监听滚动事件不起效果了,script里是这样的:

window.onscroll= function(){
                //变量t是滚动条滚动时,距离顶部的距离
                var t = document.documentElement.scrollTop;
                var scrollup = document.getElementById('tips');
                //tips是要显现与隐藏的div
                if(t>0){
                    scrollup.style.display="block";
                }else{          //恢复正常
                    scrollup.style.display="none";
                }
            }

现在根本监听不到 scrollTop的值 请问我该怎么调试 拜托啦


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

你在#app监听scroll事件啊..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...