码迷,mamicode.com
首页 > Web开发 > 详细

【2017-04-10】js来控制导航栏在滚动条拉到一定位置时显示

时间:2017-04-10 21:40:28      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:滚动   node   ack   get   ntb   test   rip   play   位置   

<html>
<head>
    <title>test</title>
</head>
<body>
    <div style="position: fixed; height: 200px; background: red; width: 100%; display: none" id="topbar"></div>
    <div style="height: 3000px;">content</div>
</body>
<script type="text/javascript">
    window.onscroll = function () {
        var top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        var node = document.getElementById(topbar);
        if (top > 500) {//500就是滚动条滚动到的位置,大于500才显示
            node.style.display = block;
        } else {
            node.style.display = none;
        }
    }
</script>
</html>

 

【2017-04-10】js来控制导航栏在滚动条拉到一定位置时显示

标签:滚动   node   ack   get   ntb   test   rip   play   位置   

原文地址:http://www.cnblogs.com/qq609113043/p/6690754.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!