0
点赞
收藏
分享

微信扫一扫

1.使用jquery来写一个当滑动到一定位置显示另外一个div(可改任意标签,根据个人情况而定),废话不多说上代码

芝婵 2022-01-06 阅读 10
<script src="http://libs.baidu.com/jquery/1.7.0/jquery.min.js"></script>
<style>
    .aa{
        display:none;
        width:750px;
        height:100px;
        background:#5e39db;
        position:fixed;
        bottom:1000px;
    }
</style>
<script>
    $(function(){
        var highly = 3000;//滚动到3000像素时显示
        var m_highly = 3000;//滚动到3000像素时隐藏
        $(window).scroll(
            function () {
                highly = Math.max(document.body.scrollTop || document.documentElement.scrollTop);//获取垂直滚动的偏移值
                // "||"这两种是为了消除标准模式和怪异模式之间的差别而做的兼容
                if (highly > m_highly) {
                    $('.aa').slideDown();//className : aa 以滑动方式显示被选元素当大于3000时显示
                }else{
                    $('.aa').slideUp();//className : aa 以滑动方式隐藏被选元素当小于3000时隐藏
                }
            })

    });
</script>
<body>
<div style="width:100%;height:5000px;background:#EEE;"></div>
<div class="aa" >div的className为aa。滚动高度3000显示</div>
</body>
举报

相关推荐

0 条评论