前端 CSS 经典:好看的标题动画

前言:好看的标题动画实现。

效果:

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        height: 100vh;
        background: #000;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      }
      p:nth-child(1) {
        color: red;
      }
      p:nth-child(2) {
        color: yellow;
      }
      p:nth-child(3) {
        color: blue;
      }

      .title {
        display: flex;
        font-size: 42px;
        text-transform: uppercase;
        letter-spacing: 5px;
        transform: rotate(-10deg);
      }
      .title span {
        opacity: 0;
        text-shadow: 1px 1px #533d4a, 2px 2px #533d4a, 3px 3px #533d4a, 4px 4px
            #533d4a, 5px 5px #533d4a, 6px 6px #533d4a;
        transform: skew(-10deg);
        animation: move 1s var(--d) cubic-bezier(0.25, 0.1, 0.57, 1.31) forwards;
      }
      @keyframes move {
        from {
          opacity: 0;
          transform: skew(-10deg) translateY(300%);
        }
        to {
          opacity: 1;
          transform: skew(-10deg) translateY(0);
        }
      }
    </style>
  </head>
  <body>
    <p class="title">这是一个标题哦</p>
    <p class="title">这是一个标题哦</p>
    <p class="title">这是一个标题哦</p>
  </body>
  <script>
    const ps = document.querySelectorAll(".title");
    ps.forEach((p) => {
      const result = p.textContent
        .split("")
        .map((letter) => `<span>${letter}</span>`)
        .join(``);
      p.innerHTML = result;
    });

    const spans = document.querySelectorAll(".title span");
    for (let i = 0; i < spans.length; i++) {
      spans[i].style.setProperty("--d", i * 0.2 + "s");
    }
  </script>
</html>
相关推荐
kyriewen8 小时前
Anthropic 估值逼近万亿美元,Claude Sonnet 5 + Claude Science 一天两连发
前端·ai编程·claude
小徐_23339 小时前
Wot UI 2.2.0 发布:Button 新增 subtle,VideoPreview 预览体验继续增强
前端·微信小程序·uni-app
天蓝色的鱼鱼11 小时前
关于 CSS 你可能不知道的属性,但关键时刻很有用
前端·css
泯泷12 小时前
第 2 篇:设计第一套字节码:Opcode、Instruction 与 Constant Pool
前端·javascript·安全
妙码生花12 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十五):优化细节、网络请求封装
前端·后端·ai编程
泯泷12 小时前
第 1 篇:从 1 + 2 开始:亲手写出第一台 JSVM
前端·javascript·安全
团团崽_七分甜12 小时前
Spring Boot 核心知识点总结
前端
lichenyang45313 小时前
从一个按钮开始,理解 ASCF 框架到底在做什么
前端
古夕13 小时前
第三方 SSO 接入实践:redirect_uri 编码、回调一致性与跨项目联调
前端·vue.js