css 文字沉没动画

katsu 发布于 2024-08-22 321 次阅读


要点

  1. clip-path 参考学习
  2. 定位 下沉和消失时间匹配
  3. 用边框画水纹

code

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>定位竖排文字到波纹中心</title>
    <style>
        body {
            background-color: #111;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
            overflow: hidden;
            /* 防止溢出 */
            position: relative;
        }

        .ripple-container {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 100px;
            height: 100px;
            transform: translate(-50%, -50%);
            /* 将波纹容器中心对齐屏幕中心 */
        }

        .ripple {
            position: absolute;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            border: 2px solid #c7d4dd;
            background-color: transparent;
            transform: rotateX(30deg);
            /* 沿X轴旋转 */
            clip-path: ellipse(50% 20% at 50% 50%);
            /* 裁剪成椭圆形,取一部分 */
            animation: ripple-effect 1.3s 1 ease-out;
            opacity: 0;
            animation-delay: 3s;
        }

        .ripple:nth-child(1) {
            animation-delay: 3s;
        }

        .ripple:nth-child(2) {
            animation-delay: 3.5s;
        }

        .ripple:nth-child(3) {
            animation-delay: 4s;
        }

        .ripple:nth-child(4) {
            animation-delay: 4.5s;
        }

        .container{
            writing-mode: vertical-rl;
            text-orientation: upright;
            font-size: 24px;
            color: rgba(255, 255, 255, 0.9);
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
            transform: rotate(5deg);
            /* 添加一个旋转角度 */
            filter: blur(0.5px);
            /* 轻微模糊效果,增加水下效果 */
            position: absolute;
            bottom: 50%;
            /* 将容器底部与波纹中心对齐 */
            left: 50%;
            /* transform: translateX(-50%) translateY(50%) rotate(5deg); */
            /* 确保文字居中对齐波纹 */
            animation: show 3s ease-in 1,
            fallAndFade 2s 3s ease-out 1;
            animation-fill-mode: forwards;
            opacity: 0;
        }

@keyframes ripple-effect {
0% {
transform: scale(0.5) rotateX(30deg);
opacity: 0.8;
}

100% {
transform: scale(2.5) rotateX(30deg);
opacity: 0;
}
}

@keyframes show {
    from{
        opacity: 0;
    }
    to{
        opacity: 1;
    }

}
@keyframes fallAndFade {
0% {
    transform: translateY(0) rotate(5deg);

    opacity: 1;
    clip-path: inset(0% 0 0% 0);
}
50% {
    transform: translateY(90px) rotate(5deg);
    opacity: 0.8;
    clip-path: inset(0% 0 50% 0); /* 从下往上逐渐消失 */
}
100% {
    transform: translateY(195px) rotate(5deg);
    opacity: 0;
    clip-path: inset(0% 0 100% 0);
}
}

    </style>
</head>

<body>
    <div class="ripple-container">
        <div class="ripple"></div>
        <div class="ripple"></div>
        <div class="ripple"></div>
        <div class="ripple"></div>
    </div>

    <div class="container">
        まごころを、君に
    </div>
</body>

</html>