逐字拆分 CSS 变量
Splitting.js,Stephen Shaw (shshaw) & Christopher Wallis,2018 年

正在布展…
它是怎么做的
- 第 1 步按单词、字符、行、网格单元拆分 DOM。
- 第 2 步每个片段获得 --word-index、--char-index 等自定义属性。
- 第 3 步父元素获得 --char-total,便于计算相对位置。
- 第 4 步动画延迟写成 calc(var(--char-index) * 40ms)。
复刻配方
一段技术配方,可以直接交给 AI 编程助手,也可以自己照着写。想指定技术栈、位置和性能预算,就把它加入实现方案。
Write a small function that walks a text node, wraps each word and each grapheme (use Intl.Segmenter) in spans, and sets style.setProperty('--i', index) on each plus '--total' on the parent. Keep an aria-label with the original string and mark spans aria-hidden. All motion then lives in CSS: transition-delay or animation-delay as calc(var(--i) * 30ms), transforms using sin()/cos() of the index for waves, and a :hover on the parent to replay. Add a line-detection pass by comparing offsetTop to expose a --line index.


