# Word Swap in a Sentence (句中换词)

A sentence stays put while one word rolls vertically like a slot machine into the next, the slot width easing along; for naming three audiences or use cases in one line.

- Ref: `video/motion-text-word-swap` (code video · motion · launch, feature, brand · any · 5s at 30fps)
- Page: https://uifino.com/en/videos/motion-text-word-swap
- Markdown: https://uifino.com/md/videos/motion-text-word-swap.md
- Preview image: https://uifino.com/videos/motion-text-word-swap/poster.jpg

## Install

- ZIP: https://uifino.com/videos/motion-text-word-swap/source.zip

A sentence stays put while one word rolls vertically like a slot machine into the next, the slot width easing along; for naming three audiences or use cases in one line.

Rendered video: https://uifino.com/videos/motion-text-word-swap/preview.mp4

## Beats

- 0-1.1s Let the viewer read the sentence and the first word: Sentence still, the slot shows the first word in the accent color, the rest in ink Camera: static. On-screen text: "Built for designers".
- 1.1-1.5s First swap: The word strip rolls up 260 px, power3.inOut, 0.4 s; both words are the same width so nothing else moves Camera: static. On-screen text: "Built for engineers".
- 1.5-2.6s Read the second word: Fully still Camera: static.
- 2.6-3s Second swap, the slot widens: Same 0.4 s roll; slot width 600 to 800 px on the same ease, the trailing text glides 200 px right, the leading text never moves Camera: static. On-screen text: "Built for founders".
- 3-5s Final hold: Fully still to the end, 2 s Camera: static.

## Parameters

- `pre` Leading text: default 为
- `word1` First word: default 设计师
- `word2` Second word: default 工程师
- `word3` Third word: default 产品经理
- `post` Trailing text: default 而做
- `accentColor` Accent color: default #2F5BFF
- `ink` Text color: default #1C1C1A
- `bg` Background: default #E8E6E1
- `fontSize` Max font size: default 200px, range 120 to 240px
- `swapOneAt` First swap start: default 1.1s, range 0.5 to 2s
- `swapTwoAt` Second swap start: default 2.6s, range 1.9 to 3.4s
- `swapDuration` Swap duration: default 0.4s, range 0.35 to 0.45s
- `swapEase` Swap ease: default power3.inOut

## Good for

- One sentence that names 3 parallel audiences or use cases
- The claim line of a launch film, hero or product intro
- Words of 3 to 4 Chinese characters or one short English word

## Not for

- Swapping the whole sentence at once
- Long words or lists of more than 3
- Each option needing its own picture

## Source files (plain text)

- https://uifino.com/videos/motion-text-word-swap/source/SPEC.md
- https://uifino.com/videos/motion-text-word-swap/source/PROMPT.md
- https://uifino.com/videos/motion-text-word-swap/source/NOTICE.md
- https://uifino.com/videos/motion-text-word-swap/source/project/assets/fonts/OFL.txt
- https://uifino.com/videos/motion-text-word-swap/source/project/compositions/swap.html
- https://uifino.com/videos/motion-text-word-swap/source/project/hyperframes.json
- https://uifino.com/videos/motion-text-word-swap/source/project/index.html

## How to use

- Copy the beats and parameters; replace only the copy, the accent color and the product screenshots.
- `PROMPT.md` has two prompts: one to reproduce this video exactly, one to learn only the technique.
- Build with HyperFrames (`/hyperframes`); the project in the ZIP is a ready starting point.

## Files

| Path | Role | Size |
| :--- | :--- | ---: |
| PROMPT.md | doc | 3.6 KB |
| SPEC.md | doc | 7.2 KB |

### PROMPT.md

```md
# PROMPT：motion-text-word-swap

## 照抄复刻
用 `/hyperframes` 做一条 1920×1080、30 fps、5 秒的动效：一句话固定不动，中间一个词像老虎机一样纵向滚动，依次换成三个词。

1. 画面：底色 `#E8E6E1`；整句一行，单字号 200px（上限；英文等更长的句子按整句最宽状态缩小：字号 = min(200, floor(1560 / 最宽状态在 100px 下的宽度 × 100))，1560px 是画面宽度的 81%）、字重 600、字距 -0.01em、行高 1.3；固定文字 `#1C1C1A`，被换的词 `#2F5BFF`，全片只有它带颜色。中文用 Noto Sans SC，西文用 IBM Plex Sans，本地 `@font-face`。没有线、边框、底色块、其他装饰。
2. 文案：「为 设计师 / 工程师 / 产品经理 而做」。英文：Built for designers / engineers / founders，后缀留空。
3. 版式：句子左端对齐，一行，垂直居中（词槽中线 y=540px）；左端 x 按最宽状态（产品经理，整句 1480px）算成左右居中，中文下是 220px。词与词之间空 0.2em（40px）。「为」从头到尾位置不变。
4. 词槽：（时间线里词带 y、模糊、词槽宽度的每个 fromTo 都要加 `immediateRender: false`，并先 `gsap.set` 到第一个词，否则第二次换词的起始值会盖掉第一次，开头会错停在工程师）一个 `overflow: hidden` 的窗口，高 260px（= 1.3 × 200），宽等于当前词的宽度；窗口里竖着排三个词，每个词占 260px 高。换词 = 整条词带上移 260px，旧词从上沿滚出，新词从下沿滚进。词槽没有边框、没有底色。
5. 节拍：0 – 1.1 秒停留在设计师；1.1 – 1.5 秒换成工程师；1.5 – 2.6 秒停留；2.6 – 3.0 秒换成产品经理；3.0 – 5.0 秒停留到结束。每次换词 0.4 秒，缓动 `power3.inOut`。每个词停留不少于 1.1 秒。
6. 宽度过渡：每次换词时，词槽宽度和滚动同起点、同时长、同缓动，从旧词宽度变到新词宽度（设计师 600px，工程师 600px，产品经理 800px），右边的「而做」跟着槽的右沿平滑移动，句子不跳。宽度要在代码里用字体加载完成后的实际字宽算出来，不要写死。
7. 拖影：不要依赖渲染器的 `data-motion-blur`（子合成里不生效）。在换词的时间线里给词带加 CSS 模糊：换词前 0.2 秒 `blur(0px)` 到 `blur(9px)`（`power2.out`），后 0.2 秒回到 `blur(0px)`（`power2.in`）；停留时完全清晰。
8. 禁止：整句一起动、换词时闪白或淡入淡出、词槽边框或底色块、下划线、弹跳、呼吸漂浮、小标签。

需要替换的地方（在 `index.html` 里 `id="swap"` 的挂载元素上写 `data-variable-values='{"pre":"Built for","post":"","word1":"designers","word2":"engineers","word3":"founders"}'` 传入；换别的中文词后要重新生成字体子集，否则缺字）：
- 文案：`pre`（前缀）、`word1`、`word2`、`word3`（三个被换的词）、`post`（后缀，可为空）。字号会按整句最宽状态缩小，保证整句不超过画面宽度的 81%。
- 颜色：`accentColor`、`ink`、`bg`。
- 时间和缓动：`swapOneAt`（1.1）、`swapTwoAt`（2.6）、`swapDuration`（0.4，范围 0.35–0.45）、`swapEase`（power3.inOut）。
- 不要加产品界面和其他文字。

## 只学手法
固定的句子里留一个 260px 高的无边框窗口，窗口里竖排三个词，整条词带每次上移一个行高，0.4 秒 `power3.inOut`，同时用同样的时间和缓动把窗口宽度从旧词宽度过渡到新词宽度，让后面的字平滑跟过去；每个词停留 1.1 秒以上，只有被换的词带强调色。
```

### SPEC.md

```md
# SPEC：motion-text-word-swap

## LOOK
- 色值（中性色 3 个，强调色 1 个）：底 `#E8E6E1`，固定文字 `#1C1C1A`，强调色 `#2F5BFF`（只染被换的那个词，面积约 8%，低于 10%）。BRIEF 里的次要字色 `#6E6C66` 和线色 `#D3D0C8` 没有用到：画面只有一句话，没有次要文字；词槽不许画边框和底色，所以也没有线。
- 字体：中文 Noto Sans SC（`assets/fonts/noto-sans-sc.woff2`），西文 IBM Plex Sans（`assets/fonts/ibm-plex-sans.woff2`），本地 `@font-face`，门禁按用到的字自动生成子集，OFL 许可。西文排在前，中文兜底。
- 字号：只有一档，默认 200px，字重 600，字距 -0.01em，行高 1.3（词槽高 260px）。西文句子更长，代码按整句最宽状态自动缩字号，见 MOTION 里的「自动排版」。
- 圆角：无。阴影：无。渐变：无。边框：无。
- 版式：整句一行，垂直居中（词槽中线 y = 540px）。句子左端对齐：「为」的位置从头到尾不变；水平位置按最宽的那个状态（产品经理）算，让最宽状态在画面里左右居中。中文默认值下整句最宽 1480px（7.4 em），左端 x = 220px。
- 词与词之间的空隙 = 0.2 em = 40px（词槽左右各一个）。

## MOTION
- 只有一个主动作：词槽里的词纵向滚动换词，像老虎机。其余文字不做任何动画。
- 词槽是一个 `overflow: hidden` 的窗口，高 260px，窗口里竖着排三个词（每个词占 260px 高）。换词 = 整条词带向上移 260px，旧词从上沿滚出，新词从下沿滚进。词槽没有边框，没有底色，窗口边缘只靠字被切掉来显示。
- 每次换词 0.4 秒，缓动 `power3.inOut`，位移 260px。
- 词槽宽度同时过渡：和滚动同起点、同时长、同缓动，所以右边的「而做」是跟着槽的右沿平滑滑过去的，不会跳。设计师（600px）和工程师（600px）一样宽，宽度不变；工程师到产品经理，宽度 600 到 800px，「而做」右移 200px。「为」从头到尾不动。
- 自动排版：先在 100px 字号下量出「为」、三个词、「而做」的宽度，整句最宽状态 = 为 + 间隙 + 最宽的词 + 间隙 + 而做；字号 = min(fontSize, floor(1560 / 最宽状态在 100px 下的宽度 × 100))。1560px 是画面宽度的 81%。中文默认值算出来是 270，取 200。英文 Built for designers / engineers / founders 整句约占 1500px，实测算出的字号约 180px（用 pre、post、word1 到 word3 变量临时换成英文，在 0.5、1.5、4.5 秒截帧确认词序是 designers、engineers、founders，整句在画面内，词槽接在 Built for 后面，强调色变量生效；改完已还原）。
- 时间线写法：词带的 y、模糊和词槽宽度的 fromTo 都带 `immediateRender: false`，并在建时间线时先用 `gsap.set` 把初始状态设成第一个词。不这样写，第二次换词的起始值会在创建时覆盖第一次，0 到 1.1 秒会错误地停在工程师。已在 draft.mp4 的 0.5、1.0 秒帧确认是设计师，2.0 秒是工程师，4.5 秒是产品经理。
- 拖影：不用渲染器的 `data-motion-blur`（子合成里的词带上试过，成片里不生效），改成在时间线里给词带加 CSS 模糊：每次换词的前 0.2 秒 `blur(0px)` 到 `blur(9px)`，缓动 `power2.out`；后 0.2 秒 `blur(9px)` 回 `blur(0px)`，缓动 `power2.in`，最糊的一帧正好是滚得最快的一帧。停留时完全清晰。已在 draft.mp4 的 1.2 秒、1.3 秒、2.8 秒帧确认有拖影，4.5 秒帧清晰。
- 停留：设计师 0 – 1.1 秒（1.1），工程师 1.5 – 2.6 秒（1.1），产品经理 3.0 – 5.0 秒（2.0），都不少于 1 秒。三个词每个 3–4 个字，读完需要 0.75–1 秒。

## 逐拍节拍表
| 拍 | 起止秒 | 画面 | 镜头 | 转场 | 屏幕文案原文 |
| --- | --- | --- | --- | --- | --- |
| hold-1 | 0.00 – 1.10 | 整句静止，词槽里是设计师 | 固定 | 无 | 为 设计师 而做 |
| swap-1 | 1.10 – 1.50 | 设计师向上滚出，工程师从下面滚进，宽度不变 | 固定 | 无 | 为 设计师 / 工程师 而做 |
| hold-2 | 1.50 – 2.60 | 整句静止，词槽里是工程师 | 固定 | 无 | 为 工程师 而做 |
| swap-2 | 2.60 – 3.00 | 工程师向上滚出，产品经理滚进，词槽加宽 200px，「而做」平滑右移 | 固定 | 无 | 为 工程师 / 产品经理 而做 |
| hold-3 | 3.00 – 5.00 | 整句静止，词槽里是产品经理，一直到结束 | 固定 | 无 | 为 产品经理 而做 |

英文版：Built for designers / engineers / founders，前缀 Built for，后缀为空，词槽左端接在 Built for 后面。

## 参数接线
全部参数都是 `project/compositions/swap.html` 根元素 `data-composition-variables` 里的变量，用户的 AI 在 `project/index.html` 里 `id="swap"` 的挂载元素上加 `data-variable-values='{"pre":"Built for","post":"","word1":"designers","word2":"engineers","word3":"founders"}'`（JSON）覆盖：
- pre（为）、word1（设计师）、word2（工程师）、word3（产品经理）、post（而做）：固定前缀、三个被换的词、固定后缀。前缀或后缀写空字符串就不留对应的间隙。
- accentColor（#2F5BFF）、ink（#1C1C1A）、bg（#E8E6E1）。
- fontSize（200）：最大字号，实际会按整句宽度缩小。
- swapOneAt（1.1）、swapTwoAt（2.6）：两次换词的起点，秒。
- swapDuration（0.4）：每次换词时长，秒，BRIEF 要求 0.35–0.45。
- swapEase（power3.inOut）：滚动和宽度过渡共用的缓动。
总时长 5 秒写在 `index.html` 和 `swap.html` 的 `data-duration`，要改就一起改。`index.html` 里的底色 `#E8E6E1` 是写死的兜底色，换底色时 `bg` 变量和它一起改。换成别的中文词后必须重新跑门禁生成字体子集。

## 禁用项
整句一起动、换词时闪白或淡入淡出、词槽边框和底色块、下划线、点击光圈、弹跳、呼吸漂浮、小标签和注释、第二种颜色。

## 已知取舍
- 画面只有一个主动作，前 1.1 秒和最后 2 秒完全静止，是 BRIEF 要求的停留时间，不是缺动作。
- 句子左端对齐，不居中：词槽宽度变化时「为」必须一动不动，只有「而做」跟着槽的右沿走。所以较短的状态（设计师、工程师）下整句偏左，右边留白 430px，换成产品经理时才左右对称。
- impeccable 会给一条「奶油色底」警告（cream-palette）：底色 #E8E6E1 是 BRIEF 指定的 stone 配色，保留，已用深色字、单一蓝色强调色和大字号拉开，没有套奶油底的衬线加暖色那一套。
- 词槽窗口的上下沿会把滚动中的字切掉，切口没有任何线或底色；这是 BRIEF 要的「老虎机」滚动，不算裁字。
- 窗口高 260px，字高约 200px，比字多出上下各约 30px 的空；滚动中下一个词的字头会提前从窗口边缘露出来，是老虎机窗口的预期样子，不是 bug。
- 单个子合成里的词带比窗口高，hf-check 的溢出提示已用 data-layout-allow-overflow 标在词带上。
- 字体子集按默认中文文案和 ASCII 生成，换成别的中文词要重新跑门禁。
- 时间线要等字体加载完才注册（要先量字宽），所以代码里用了 document.fonts.load 的 Promise。
```
