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

Posted 疯丶无度

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017-04-10js来控制导航栏在滚动条拉到一定位置时显示相关的知识,希望对你有一定的参考价值。

<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-10js来控制导航栏在滚动条拉到一定位置时显示的主要内容,如果未能解决你的问题,请参考以下文章