仕組み
Each character is an inline box sized by its final glyph. While it churns, the final glyph turns transparent and a random one is centred over it in a lighter accent colour, so the line never reflows and the eye reads it as working. Settle times follow the reading order with a seeded jitter, so the text resolves as a soft wave and the same way every time; settling is a hard cut, crisp like a split-flap board. Glyphs change every 45ms rather than every frame, which reads as deliberate instead of noisy.
向いている場面
- Short headings or labels in technical, security or launch contexts.
- Links and menu items that should react to hover with character.
向かない場面
- Body text or anything longer than a line or two.
- Long passages in Chinese or Japanese: wide characters churn through narrow glyphs, so keep it to short headings there.
使い方
import { useState } from 'react'
import { ScrambleText } from './ScrambleText.jsx'
export function ReleaseHeading() {
return <h2><ScrambleText text="Faster builds, fewer surprises" trigger="view" /></h2>
}
// Drive it from a parent, such as a whole link row
export function LinkRow({ label }) {
const [play, setPlay] = useState(0)
return (
<a href="/changelog" onPointerEnter={() => setPlay((p) => p + 1)} onFocus={() => setPlay((p) => p + 1)}>
<ScrambleText text={label} trigger="none" play={play} />
</a>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
text | string | — | Final text. |
trigger | 'view' | 'hover' | 'mount' | 'none' | 'view' | When it scrambles: entering the view (once), pointer enter or focus inside, on mount, or only through play. |
play | any | — | Any change replays it, such as a counter. |
duration | number | 900 | Time until the last character settles, in ms. |
charset | 'letters' | 'symbols' | 'digits' | 'binary' | string | 'letters' | Glyphs to churn through, or your own string. |
tick | number | 45 | Milliseconds between glyph changes. |
as | ElementType | 'span' | Element to render. |
アクセシビリティ
- The final text sits in a visually hidden span, so screen readers read it once and never hear the random glyphs; the animated characters are aria-hidden.
- Hover triggers also fire on focus inside, so keyboard users get the same effect.
- The animation is short (under a second by default) and does not repeat on its own.
- Reduced motion skips the scramble entirely; the final text is always shown.
モーション
Glyphs change every 45ms; characters settle over the duration (900ms by default), 70% by position and 30% by a seeded jitter.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
ScrambleText.jsxscramble-text.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。



