Word blur reveal
逐词模糊浮现
The words of a headline sharpen into view one after another, from blurred and transparent to clear.
Also searched as: 标题一个词一个词从模糊变清楚, 文字逐词模糊淡入, 大标题的词依次浮现出来, 字从虚到实一段段出现
- Placement
- Hero heading
- Mood
- Soft, Refined
- Trigger
- 进入屏幕
- Site types
- 个人网站, 作品集, 品牌官网
How it works & accessibility
splitWords wraps each word in an inline span with Intl.Segmenter (spaces as a fallback) without changing the text, then each span animates opacity 0 to 1 and filter blur(N px) to blur(0) with a per-word delay; screen readers still read one sentence, fill: backwards keeps the text visible if the script fails, and reduced motion skips the animation.
Best for: Hero heading (进入屏幕).
Reduced motion: 不播放动画,整句直接显示
Mobile & touch: 和桌面一样;模糊每一帧都要重画,只给标题用,别给大段正文用
Key parameters
| Parameter | Key | Default | Range | Notes |
|---|---|---|---|---|
| 每个词的时长 | duration | 700ms | — | — |
| 词与词间隔 | stagger | 90ms | — | — |
| 第一个词延迟 | delay | 100ms | — | — |
| 起始模糊 | blur | 12px | — | — |
| 缓动 | easing | cubic-bezier(0.22, 1, 0.36, 1) | — | — |
Ready-to-paste AI prompt
Add “Word blur reveal” to the hero heading in my project: splitWords wraps each word in an inline span with Intl.Segmenter (spaces as a fallback) without changing the text, then each span animates opacity 0 to 1 and filter blur(N px) to blur(0) with a per-word delay; screen readers still read one sentence, fill: backwards keeps the text visible if the script fails, and reduced motion skips the animation.
Parameters: duration: 700ms, stagger: 90ms, delay: 100ms, blur: 12px, easing: cubic-bezier(0.22, 1, 0.36, 1).
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/word-blur-reveal.md (canonical specification and reference code).Dependency-free reference code
CSS
/* 逐词模糊浮现:每个词是行内的小段,模糊时不挤动旁边的字(filter 不改变布局)。不需要别的样式:
字默认就是最终的样子,动画开始前那一瞬才由脚本变模糊、透明 */
.wbr-word {
display: inline-block;
}JavaScript
// 逐词模糊浮现(Word blur reveal)· 原生 JS,不依赖任何库。
// 同类效果见 Animation Handbook 的 word-by-word-reveal(MIT);本站按通用做法自己实现,没有复制代码。
// 用法:直接调 wordBlurRevealOnEnter(标题) 或 wordBlurReveal(标题),它们会先用 splitWords 把标题按词拆成 <span class="wbr-word">
//(拆过的不再拆;也可以自己手动包好 <span class="wbr-word">)。
// - 每个词从透明、模糊(filter: blur)变清楚,第 i 个词晚 delay + i * stagger 毫秒开始。
// - 选项:duration(每个词的时长,ms)、stagger(词与词间隔,ms)、delay(第一个词延迟,ms)、blur(起始模糊,px)、easing(缓动)。
// - 开启"减少动态"时不播放,整句直接显示;动画用 fill: 'backwards',脚本出错或没执行时字照样看得见(不要先用 CSS 把字藏起来)。
// - ignoreReducedMotion 只给"用户主动点播放"的演示用,网站自己的标题不要打开它。
// - 拆开以后还是同一句话(textContent 不变):词是行内的 span,读屏照常连着念;不加 aria-label、aria-hidden。
// 把 root 里的文字(包括链接、加粗这些标签里面的)按词拆成 <span class="wbr-word">。中文、英文都按浏览器的分词(Intl.Segmenter),
// 不支持时按空格拆;词之间的空格原样留着,标点跟着前一个词;<br>、链接、加粗这些标签原样留着,词包在它们里面。
// 已经拆过(有 .wbr-word)的不再拆。返回拆出来的词(按页面上的顺序)。
export function splitWords(root, locale = root.closest('[lang]')?.getAttribute('lang') || undefined) {
const done = root.querySelectorAll('.wbr-word');
if (done.length) return [...done];
const seg = typeof Intl !== 'undefined' && Intl.Segmenter ? new Intl.Segmenter(locale, { granularity: 'word' }) : null;
const pieces = (text) => (seg
? [...seg.segment(text)].map((s) => ({ text: s.segment, space: /^\s+$/.test(s.segment), word: s.isWordLike }))
: text.split(/(\s+)/).filter(Boolean).map((t) => ({ text: t, space: /^\s+$/.test(t), word: true })));
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
acceptNode: (n) => (n.parentElement?.closest('script, style') ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT),
});
const nodes = [];
for (let n = walker.nextNode(); n; n = walker.nextNode()) if (n.textContent.trim()) nodes.push(n);
const words = [];
for (const node of nodes) {
const frag = document.createDocumentFragment();
let last = null;
for (const p of pieces(node.textContent)) {
if (p.space) { frag.append(p.text); last = null; continue; }
if (!p.word && last) { last.textContent += p.text; continue; }
last = document.createElement('span');
last.className = 'wbr-word';
last.textContent = p.text;
frag.append(last);
words.push(last);
}
node.replaceWith(frag);
}
return words;
}
// 播一次:root 里每个词(没拆过的先自动拆)依次从模糊变清楚。返回一个清理函数:调用它会停掉动画,字回到最终状态。
export function wordBlurReveal(root, {
duration = 700,
stagger = 90,
delay = 100,
blur = 12,
easing = 'cubic-bezier(0.22, 1, 0.36, 1)',
ignoreReducedMotion = false,
} = {}) {
if (!ignoreReducedMotion && matchMedia('(prefers-reduced-motion: reduce)').matches) return () => {};
const words = splitWords(root);
const animations = words.map((word, i) => word.animate(
[{ opacity: 0, filter: `blur(${blur}px)` }, { opacity: 1, filter: 'blur(0px)' }],
{ duration, delay: delay + i * stagger, easing, fill: 'backwards' },
));
return () => animations.forEach((a) => a.cancel());
}
// 标题进入屏幕时播放一次。
// 离屏幕底边还有 40px 时就开始(碰到一点就算):动画的第一帧是模糊、透明的,等露出一截再开始,会先完整露一下、再消失、再出现;
// root: document 让提前量按元素所在页面自己的视口算,放在 iframe 里也管用。
// 返回一个函数:调用它停止观察(还没进屏幕的就不播了),已经开始播的动画也一起停掉(字回到最终状态)
export function wordBlurRevealOnEnter(root, options) {
let cancel = null;
const io = new IntersectionObserver(([entry]) => {
if (!entry.isIntersecting) return;
io.disconnect();
cancel = wordBlurReveal(root, options);
}, { root: document, threshold: 0, rootMargin: '0px 0px 40px 0px' });
io.observe(root);
return () => { io.disconnect(); cancel?.(); };
}HTML
<!-- 逐词模糊浮现:标题照常写,脚本会先把它按词拆开,进入屏幕时一个词一个词地变清楚 -->
<h1 id="hero-title">把想法做成能用的东西</h1>
<script type="module">
import { wordBlurRevealOnEnter } from './word-blur-reveal.js';
wordBlurRevealOnEnter(document.getElementById('hero-title'), { duration: 700, stagger: 90, blur: 12 });
</script>