圆形的元素随滚动条下拉实时渐变缩小,一直到导航条固定时停止缩小;当滚动条上拉到导航条没有固定时渐变放大到原来的大小
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .fixed{
            position: fixed;
            top: 0;
        }
    </style>
</head>
<body>
<p style="height:200px;background-color:#EFE4B0;"></p>
<p id="fixed" style="height:40px;width:100%;background-color:#7092BE;color:#fff;z-index:999;">这个p到达顶部时悬浮在顶部,不到顶部不悬浮</p>
<p style="height:2000px;background-color:#C3C3C3;">
    <p style="height:300px;background-color:#E6F8AE;">
        <p id="avatar" style="height:100px;width:100px;border-radius:50%;background-color:#99D9EA;-webkit-transform: scale(1);z-index:-1">
        </p>
    </p>
</p>
<script type="text/javascript">
    var fixedDom = document.getElementById('fixed');
    var fixedTop = fixedDom.offsetTop;
    var bodyDom = document.body;
    window.addEventListener('scroll',function(){
        fixedDom.classList[fixedTop - bodyDom.scrollTop < 1 ? 'add' : 'remove']('fixed');
    });
    </script>
</body>
</html>
                            
                                    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证0级讲师