主要CSS

  • animation
  • transform: scale()
  • opacity
  • nth-child()

效果展示

动画

代码

<div>
    <style>
        .ripple {
            width: 200px;
            height: 200px;
            position: absolute;
            top: calc(50% - 100px);
            left: calc(50% - 100px);
            border-radius: 50%;
            background-color: blueviolet;
        }
        /* 根据需求自定义 */
        .content{
            position: absolute;
            z-index: 99;
            /* 与.ripple的top和left相同 */
            top: calc(50% - 100px);
            left: calc(50% - 100px);

            width: 200px;
            height: 200px;
            border-radius: 50%;
            background-color: rgb(42, 42, 180);

            font-size: 20px;
            font-weight: bold;
            color: #FFF;
            text-align: center;
            line-height: 200px;
        }
        .ripple:nth-child(2){
            animation: wave 1s linear infinite;
        }
    
        .ripple:nth-child(3){
            animation: wave 2s linear infinite;
        }
    
        .ripple:nth-child(4){
            animation: wave 3s linear infinite;
        }
        .ripple:nth-child(5){
            animation: wave 4s linear infinite;
        }

        @keyframes wave {
            from {
                opacity: 1;
                transform: scale(1);
            }

            to {
                opacity: 0;
                transform: scale(1.5);
            }
        }
    </style>
    <div class="box">
        <div class="content">内容</div>
        <div class="ripple"></div>
        <div class="ripple"></div>
        <div class="ripple"></div>
        <div class="ripple"></div>
        <div class="ripple"></div>
    </div>
</div>

实现的逻辑就是通过animation动画重复将这些元素放大1.5倍,同时将元素变为完全透明,从而达到波纹扩散的效果

最后修改:2024 年 05 月 12 日
如果觉得我的文章对你有用,请随意赞赏