YL

TEXT EFFECT

变形文字Morphing Text

同一位置的多组词交替:旧的放大模糊消失,新的从缩小清晰浮现。Magic UI 的 Morphing Text 与 ReactBits 的 Word Rotate 同类。

中英对照

中文
变形文字
英文
Morphing Text
别名
Word Morph、Text Swap、Rotating Words
一句话
同一位置的多组词交替:旧的放大模糊消失,新的从缩小清晰浮现。Magic UI 的 Morphing Text 与 ReactBits 的 Word Rotate 同类。

效果预览

Design, Build, Ship

适合用在哪

首屏标题里轮换多个卖点(「让想法 上线/变现/被看见」),节省版面又能多说几件事。

不适合:候选词含义差别很大、用户必须全部看到的信息(套餐名、支持的平台列表):一次只露一个词,等一轮要五六秒,很多人只会看到第一个;以触屏为主、用户快速滑过首屏的页面,轮换的词大多没人看完。

和相近模式的区别

翻转词Flip Words

翻转词有一个带浅底和圆角的固定词位,候选词绕 X 轴像翻牌一样翻进翻出,强调「这里是一个可替换的变量」,适合句子中间的一个词,只动 transform 和 opacity;变形文字没有词位边框,旧词放大模糊消失、新词从缩小清晰浮现,像镜头切换,过渡更柔和,适合大标题里的卖点轮换,代价是要多算一层 blur。

容易踩的坑

  • 候选词长度差异大时容器宽度不固定,整行标题会左右跳动。
  • 读屏只能读到当前可见词或全部叠放的词,需提供完整静态文案。
  • 轮换超过 4 个卖点,用户等一整轮要十几秒,后面的根本没人看到。

设计提示词 · Prompt

变形文字(Morphing Text):把候选词都放在同一个 grid 单元格(grid-area:1/1)里叠起来。每个词动画 5.4s cubic-bezier(.4,0,.2,1):0% 时 opacity:0、filter:blur(8px)、scale(.85),10%-28% 完全清晰居中,34% 后 opacity:0、blur(8px)、scale(1.12)。词的 animation-delay 依次错开 1.8s(单段时长 = 总时长 ÷ 词数),保证任一时刻只有一个词可见。一轮 5.4 秒已超过 5 秒,持续轮换必须提供可见的暂停按钮(悬停与聚焦时也暂停);不加按钮时改用 JS 切换类名,每 1.4 秒换一个词、只轮一轮就停回第一个词,整段在 5 秒内结束(WCAG 2.2.2)。轮换词组加 aria-hidden,另用视觉隐藏文本写出全部候选词。容器设固定高度与 overflow:hidden 防抖动。
Morphing Text: stack all candidate words in the same grid cell (grid-area:1/1). Each word animates 5.4s cubic-bezier(.4,0,.2,1): at 0% opacity:0, filter:blur(8px), scale(.85); fully sharp and centered at 10%-28%; after 34% opacity:0, blur(8px), scale(1.12). Stagger the words' animation-delay by 1.8s each (segment duration = total duration ÷ word count) so only one word is visible at any moment. One round takes 5.4s, longer than 5 seconds, so continuous rotation needs a visible pause button (also pausing on hover and focus); without a button, switch classes with JS every 1.4s, rotate through once and stop on the first word so the whole sequence ends within 5 seconds (WCAG 2.2.2). Mark the rotating group aria-hidden and list all candidate words in visually hidden text. Give the container a fixed height and overflow:hidden to prevent jitter.

可复制 CSS

自包含的最小实现,粘贴到空白页面即可生效;类名可以按项目规范改名。

/* <h1>让想法<span class="morph" aria-hidden="true"><span class="morph__word is-current">上线</span><span class="morph__word">变现</span><span class="morph__word">被看见</span></span><span class="morph__sr">上线、变现、被看见</span></h1>
   JS 每 1.4 秒把 .is-current 移给下一个词,轮完一轮回到第一个词后停止;旧词同时加 .is-leaving,transitionend 后移除;没有 JS 时停在第一个词 */
.morph {
  display: inline-grid;
  justify-items: start;
}
/* 所有词叠在同一格,宽度按最长的词自动预留 */
.morph__word {
  grid-area: 1 / 1;
  opacity: 0;
  filter: blur(8px);
  transform: scale(.85);
  transition:
    opacity .5s cubic-bezier(.4, 0, .2, 1),
    filter .5s cubic-bezier(.4, 0, .2, 1),
    transform .5s cubic-bezier(.4, 0, .2, 1);
}
.morph__word.is-current { opacity: 1; filter: none; transform: none; }
.morph__word.is-leaving { transform: scale(1.12); }
.morph__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
  .morph__word { transition: none; }
}

演示 HTML 结构

<div class="s d-center">
  <div class="tx-morph"><i aria-hidden="true">Design</i><i aria-hidden="true">Build</i><i aria-hidden="true">Ship</i><span class="d-sr-only">Design, Build, Ship</span></div>
</div>

无障碍与性能

无障碍

  • 轮换的词组整体 aria-hidden="true",视觉隐藏的 .morph__sr 写出全部候选,读屏读到「让想法上线、变现、被看见」,不会只读到某一个词或把叠放的词连成一串。
  • 轮换属于自动开始的移动内容:不加暂停按钮时只轮一轮(3 个词每 1.4 秒一换,约 4.7 秒后停回第一个词),控制在 SC 2.2.2 的 5 秒以内;需要持续轮换时,必须提供可见的暂停按钮,悬停和聚焦时也暂停。prefers-reduced-motion: reduce 时 JS 不启动轮换,CSS 也去掉过渡。
  • 没有 JS 时第一个词带 .is-current,标题完整可读。

性能

  • 任一时刻最多两个词在过渡,blur(8px) 只作用在一个词的面积上;不要把整行标题一起模糊。
  • 轮换用 setTimeout 驱动,页面切到后台(visibilitychange 且 document.hidden 为 true)时停止计时,回来再继续。

常见问题

变形文字的英文是什么?

变形文字的英文是 Morphing Text。常见英文别名还包括 Word Morph、Text Swap、Rotating Words。

Morphing Text 的中文是什么?

Morphing Text 的中文是「变形文字」。同一位置的多组词交替:旧的放大模糊消失,新的从缩小清晰浮现。Magic UI 的 Morphing Text 与 ReactBits 的 Word Rotate 同类。

变形文字最少需要哪些 JS?

保存当前序号 i,用 setTimeout 每 1.4 秒执行一次:当前词移除 .is-current、加 .is-leaving,下一个词加 .is-current;在旧词的 transitionend(只处理 propertyName 为 opacity 的那次)里移除 .is-leaving,它会在透明状态下回到 scale(.85) 的待命位置。轮完一轮回到第一个词后停止计时(整段约 4.7 秒);需要持续轮换时把间隔放宽到 1.8 秒并提供暂停按钮:按钮切换一个 paused 标记并清除计时器,同时切换自身的 aria-pressed;启动前检查 matchMedia('(prefers-reduced-motion: reduce)').matches,命中就不启动。

为什么不用纯 CSS 的 animation-delay 错开来做?

纯 CSS 版能循环,但做不到两件事:停在一个完整的词上(动画结束时每个词都回到透明的终点帧),以及干净地暂停(animation-play-state: paused 可能正好停在半模糊的过渡帧)。而且时序要手算:每个词的递延是「总时长 ÷ 词数」,主 prompt 里 5.4 秒、3 个词对应 1.8 秒的递延,增减一个词就要同时改总时长、递延和关键帧百分比。用 JS 切换类名,词数可以随意增减,暂停和停止也都落在完整的词上。

常见搭配

同一页面里经常和「变形文字」一起出现的模式,可以收藏后用「组合收藏为整页提示词」一起交给 AI。

所属设计风格

「变形文字」是这些整体设计风格的常见组成部分,在设计风格词典里可以看到整页效果。

标签