Skip to content

故障效果

故障效果的CSS动画效果,纯CSS实现,无需JavaScript。

实时预览

GLITCH

代码

css
.glitch {
  font-size: 40px;
  font-weight: 900;
  text-transform: uppercase;
  color: #fff;
  position: relative;
  display: inline-block;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.glitch::before {
  color: #ff00c8;
  animation: glitch-1 2s infinite linear alternate-reverse;
  clip-path: inset(0 0 60% 0);
}

.glitch::after {
  color: #00fff9;
  animation: glitch-2 2s infinite linear alternate-reverse;
  clip-path: inset(60% 0 0 0);
}

@keyframes glitch-1 {
  0%   { transform: translate(0); }
  20%  { transform: translate(-3px, 2px); }
  40%  { transform: translate(3px, -1px); }
  60%  { transform: translate(-2px, -2px); }
  80%  { transform: translate(2px, 1px); }
  100% { transform: translate(0); }
}

@keyframes glitch-2 {
  0%   { transform: translate(0); }
  20%  { transform: translate(2px, -2px); }
  40%  { transform: translate(-3px, 1px); }
  60%  { transform: translate(1px, 2px); }
  80%  { transform: translate(-2px, -1px); }
  100% { transform: translate(0); }
}
html
<span class="glitch" data-text="GLITCH">GLITCH</span>

纯 CSS 实现的故障效果文字动画效果——通过渐变、阴影、滤镜和变换等 CSS 属性让文字产生视觉动效。所有文字内容保持可选中、可复制、对搜索引擎完全可见。

快速使用

  1. 复制 CSS 代码到你的样式文件中
  2. 在 HTML 中放入对应的文字结构(注意逐字效果需要每个字符包裹 <span>
  3. 根据你的文字内容调整 animation-delay 和文字数量
  4. 修改颜色和字号以匹配你的品牌风格

使用场景

  • 页面主标题:用渐变文字、霓虹发光或逐字弹跳效果吸引用户注意力
  • 品牌名称/Logo:3D 文字或故障效果传递技术与设计感
  • 营销活动页:彩虹文字、闪烁效果营造促销紧迫感
  • 技术博客/文档:打字机效果展示代码片段或技术标语

常见问题

Q: 文字动画在哪些浏览器下兼容? A: 大部分效果所有现代浏览器都支持。需注意:background-clip: text-webkit- 前缀;@property 仅 Chrome/Edge 支持。渐变文字和霓虹发光效果建议加降级方案。

Q: 动画文字会影响 SEO 吗? A: 不会。文字内容仍然在 HTML 中正常渲染,搜索引擎能完整抓取。CSS 动画只影响视觉呈现,不改变 DOM 结构和文本可访问性。

Q: 如何让逐字动画适配任意长度的文字? A: 用 JavaScript 动态给每个字符包裹 <span> 并设置 animation-delay: calc(var(--i) * 0.05s),或使用 CSS animation-delay 配合 nth-child 错位。

浏览器兼容性

浏览器兼容性
Chrome / Edge✅ 完全支持(含 @property
Firefox✅ 基本支持(不含 @property
Safari✅ 基本支持(需 -webkit-background-clip
移动端浏览器✅ 完全支持
IE 11❌ 渐变文字等高级效果不支持

使用说明

属性说明
data-textMust match the visible text; used by ::before and ::after
clip-path: inset()Slices each pseudo-element to show only part of the shifted text
colorCyan #00fff9 and magenta #ff00c8 for classic RGB-split look
transform: translate()Creates the offset distortion per slice

Tip: Add more keyframe steps with larger offsets for a more chaotic effect, or reduce them for subtlety.