全部效果自动播放与循环

故障字效

Glitch Text

字形的几条切片短暂错开,边缘出现偏移的彩色通道。

播放或暂停演示

适用场景

强调游戏标题、音乐封面或短句风格标题。 把切片错位留给短标题,两次变化之间留足时间阅读稳定的字形。

应用示例

一款以损坏电台为题材的解谜游戏先显示稳定的白色标题。几条细切片短暂横移并露出红蓝边,再恢复原状,一旁的开始菜单保持稳定。

AI 提示词

给【目标标题】加故障字效。保留一个可读文本节点,把两个装饰副本裁成窄横条。让切片只在间隔较长的短时段里移动几像素,减少动态时显示稳定文字。

示例代码

保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。

查看 HTML
<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>故障字效</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .glitch-word { position: relative; font: 800 clamp(22px, 13vw, 38px)/1.2 system-ui; letter-spacing: .1em; text-shadow: 0 0 13px #b6a0ff6e; }
    .glitch-word span { position: absolute; inset: 0; color: #91f6ea; clip-path: inset(24% 0 58%); transform: translateX(-2px); animation: slice-shift 3s steps(1) infinite; }
    .glitch-word span:nth-child(2) { color: #ff7dac; clip-path: inset(58% 0 17%); transform: translateX(2px); animation-delay: -.1s; }
    @keyframes slice-shift {
      0%, 51%, 68%, 100% { translate: 0; }
      53%, 62% { translate: 4px -1px; }
      57%, 66% { translate: -5px 1px; }
    }

    .motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
    .motion-specimen {
      display: grid;
      place-items: center;
      width: min(100%, 295px);
      height: 108px;
      position: relative;
      isolation: isolate;
    }
    .motion-example [data-motion] { animation-play-state: paused; }
    .motion-example[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .motion-example [data-motion] { animation: none; }
      .motion-example [data-loop-toggle] { display: none; }
    }

    @media (prefers-reduced-motion: reduce) { .glitch-word span { display: none; } }
  </style>
</head>
<body>
  <main class="demo">
    <div class="motion-example">
      <div class="motion-specimen" aria-hidden="true"><div class="glitch-word">SIGNAL<span data-motion>SIGNAL</span><span data-motion>SIGNAL</span></div></div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
    </div>
  </main>
  <script>
    const example = document.querySelector('.motion-example');
    const toggle = example.querySelector('[data-loop-toggle]');

    toggle.addEventListener('click', () => {
      const playing = example.toggleAttribute('data-playing');
      toggle.textContent = playing ? "暂停演示" : "播放演示";
    });
  </script>
</body>
</html>

UI Skills 原创示例