浏览器滚动到一段距离,绝对定位的导航出现

来源:互联网 发布:mac地址 有问题 编辑:程序博客网 时间:2024/06/06 05:06
具体效果是,浏览器滚动到一定距离的时候,fixed绝对定位的导航会显示,当滚动到小于这个距离的时候,导航会隐藏。


js部分:
<script>
    function getTop() {
        var mytop = $(document).scrollTop();
        if (mytop > 400) {
            $(".fixed_banner").css({
                'display': 'block',
                'top': 0,
            });
        } else {
            $(".fixed_banner").css('display', 'none');
        }
        setTimeout(getTop);
    }

    getTop();
</script>

css部分
.fixed_banner {
    position: fixed;
    bottom: 10px;
    height: 100px;
    z-index: 10000;
    display: none;
}

0 0
原创粉丝点击