Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

feat: move Split Text Reveal to the guided-steps page

matin250326b67ac0
diff --git a/animations/02-entrance-and-exit/split-text-reveal/README.md b/animations/02-entrance-and-exit/split-text-reveal/README.md
index 04f0c17e..ea64dd35 100644
--- a/animations/02-entrance-and-exit/split-text-reveal/README.md
+++ b/animations/02-entrance-and-exit/split-text-reveal/README.md
@@ -43,11 +43,12 @@ Per-unit animation is swappable via `data-anim` (fade-up, fade, scale, rotate);
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Split mode | Words | Characters give the finest cascade, words a readable rhythm, lines a block reveal |
-| Animation per unit | Fade up | The small entrance each piece plays: fade up, fade, scale or rotate |
-| Stagger delay | 30ms | Delay between pieces; small values ripple, large values feel deliberate |
-| Duration per unit | 500ms | How long each piece takes to animate |
-| Easing | Smooth | The curve each piece uses; Springy adds a small settle |
+| Split into | Words | Letters give the finest cascade, words a readable rhythm, lines a block reveal |
+| How each piece appears | Fade up | The small entrance each piece plays: fade up, fade, grow or flip |
+| Delay between pieces | Medium | The wait between pieces: short is 10ms, medium 30ms and long 100ms; small values ripple, large values feel deliberate |
+| Speed | Normal | How long each piece takes: slow is 800ms, normal 500ms and fast 300ms |
+| Feel | Smooth | The curve each piece uses; Springy adds a small settle, Even keeps one steady pace |
+| Your text | Design beyond the obvious | The text that is split and revealed |
## Production notes
- **Total time = units × stagger + duration.** Character mode on a long string multiplies fast — 40 chars × 30ms + 500ms is nearly 1.7s. Cap the stagger or switch to words/lines for longer copy so the tail does not drag.
@@ -57,7 +58,7 @@ Per-unit animation is swappable via `data-anim` (fade-up, fade, scale, rotate);
- **Library equivalents:** Splitting.js and GSAP's SplitText both do the DOM splitting for you (SplitText also handles the ARIA and re-split-on-resize); Framer Motion uses `staggerChildren` on a parent variant with child `motion.span`s; Motion One's `stagger()` helper generates the per-element delay.
## See also
-- [Slide Up Reveal](../slide-up-reveal/) — the clipped line-rise this reuses in `lines` mode
-- [Letter By Letter Stagger](../letter-by-letter-stagger/) — char-split cascade in depth
-- [Word By Word Reveal](../word-by-word-reveal/) — word-split cascade in depth
-- [Fade In / Fade Out](../fade-in-out/) — the un-staggered baseline
+- [Slide Up Reveal](../slide-up-reveal/) — whole lines rise from behind an invisible edge
+- [Letter-by-Letter Stagger](../letter-by-letter-stagger/) — one letter at a time, or typed out
+- [Word-by-Word Reveal](../word-by-word-reveal/) — one word at a time, at a reading pace
+- [Fade In / Fade Out](../fade-in-out/) — the whole text fades in at once
diff --git a/animations/02-entrance-and-exit/split-text-reveal/index.html b/animations/02-entrance-and-exit/split-text-reveal/index.html
index bb9e2723..a4d82cce 100644
--- a/animations/02-entrance-and-exit/split-text-reveal/index.html
+++ b/animations/02-entrance-and-exit/split-text-reveal/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Split Text Reveal — Animation Handbook</title>
- <meta name="description" content="Text split into chars, words, or lines — each piece animates with a staggered delay via --index.">
+ <meta name="description" content="Text breaks into pieces that appear one after another. Best for headlines.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/split-text-reveal/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,23 +12,19 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Split Text Reveal — Animation Handbook">
- <meta property="og:description" content="Text split into chars, words, or lines — each piece animates with a staggered delay via --index.">
+ <meta property="og:description" content="Text breaks into pieces that appear one after another. Best for headlines.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/split-text-reveal/">
<meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Split Text Reveal — Animation Handbook">
- <meta name="twitter:description" content="Text split into chars, words, or lines — each piece animates with a staggered delay via --index.">
+ <meta name="twitter:description" content="Text breaks into pieces that appear one after another. Best for headlines.">
<meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
- <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Split Text Reveal", "name": "Split Text Reveal", "description": "Text split into chars, words, or lines — each piece animates with a staggered delay via --index.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/split-text-reveal/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Split Text Reveal"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Split Text Reveal", "name": "Split Text Reveal", "description": "Text breaks into pieces that appear one after another. Best for headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/split-text-reveal/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Split Text Reveal"}</script>
<style>
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#5fd88a;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--dur:500ms;--ease:cubic-bezier(.2,.7,.3,1);--stagger:30ms}
+ :root{--ui-accent:#5fd88a;--dur:500ms;--ease:cubic-bezier(.2,.7,.3,1);--stagger:30ms;--hb-stage-h:auto;--hb-stage-h-phone:auto}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}
- header{margin-bottom:20px}
- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:center;justify-content:center;overflow:hidden;padding:clamp(20px,4vw,48px)}
+ .stage{display:flex;align-items:center;justify-content:center;overflow:hidden;background:#0b0b0d;padding:clamp(20px,4vw,48px);
+ min-height:clamp(300px,calc(100vh - 420px),440px);min-height:clamp(300px,calc(100svh - 420px),440px)}
#text-target{font-family:monospace;font-size:clamp(24px,4.5vw,48px);font-weight:bold;text-align:center;line-height:1.35;max-width:560px;word-break:break-word}
/* shared unit styles — animation-type overrides below */
.unit{display:inline-block;
@@ -48,114 +44,167 @@
/* word spacing */
[data-mode="words"] .unit{margin-right:0.28em}
[data-mode="chars"] .unit{margin-right:0.01em}
+ @media(max-width:600px){.stage{min-height:300px}}
@media(prefers-reduced-motion:reduce){.unit,.unit-inner{transition:opacity 300ms linear!important;transform:none!important}[data-mode="lines"] .unit{opacity:0}.splitting.in .unit{opacity:1}}
- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
- .kv .v{color:var(--ui-text)}
- .div{height:1px;background:var(--ui-border)}
- .sr{display:flex;align-items:center;gap:6px;font-size:10px}
- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
- .sv{width:38px;text-align:right;color:var(--ui-text)}
- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- .seg{display:flex;gap:3px;flex-wrap:wrap}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
- .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px;border-radius:4px;width:100%;min-height:44px}
- .btn-row{display:flex;gap:6px}
- button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
- button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
- @media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}.seg button{min-height:44px}:root{--stage-h:480px}}
</style>
-<link rel="stylesheet" href="../../../assets/css/handbook.css">
-<script src="../../../assets/js/handbook.js" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css">
+ <script src="../../../assets/js/demo-page.js" defer></script>
</head>
-<body class="hb" data-hb-autoplay>
-<nav class="hb-bar" aria-label="Animation Handbook"><a class="hb-home" href="../../../">← <span>Animation Handbook</span></a><span class="hb-pager"><a href="../curtain-reveal/" rel="prev" aria-label="Previous: Curtain Reveal">‹ <span class="hb-name">Curtain Reveal</span></a><a href="../letter-by-letter-stagger/" rel="next" aria-label="Next: Letter-by-Letter Stagger"><span class="hb-name">Letter-by-Letter Stagger</span> ›</a></span></nav>
-<main class="hb-view">
- <div class="stage">
- <div id="text-target" class="splitting" data-mode="words" data-anim="fade-up">Design beyond the obvious</div>
- </div>
- <aside class="hb-side">
- <header class="hb-head">
- <p class="hb-cat">02.07 · Entrance &amp; Exit</p>
- <h1>Split Text Reveal</h1>
- <p class="hb-lede">Text breaks into pieces that animate in one after another.</p>
- </header>
- <section class="hb-settings" aria-label="Settings">
- <h2 class="hb-label">Settings</h2>
- <div class="lbl">State</div>
- <div class="kv"><span>Status</span><span class="v" id="st">hidden</span></div>
- <div class="kv"><span>Total time</span><span class="v" id="total-time">—</span></div>
- <div class="div"></div>
- <div class="lbl">Split mode</div>
- <div class="seg" id="mode-seg">
- <button data-m="chars">Chars</button>
- <button data-m="words" class="on">Words</button>
- <button data-m="lines">Lines</button>
+<body class="hb" data-hb-kind="once" data-hb-autoplay>
+<nav class="hb-bar" aria-label="Animation Handbook">
+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
+ <span class="hb-pager"><a href="../curtain-reveal/" rel="prev" aria-label="Previous: Curtain Reveal"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Curtain Reveal</span></a><a href="../letter-by-letter-stagger/" rel="next" aria-label="Next: Letter-by-Letter Stagger"><span><span class="hb-dir">Next: </span>Letter-by-Letter Stagger</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">02.07 · Entrance &amp; Exit</p>
+ <h1>Split Text Reveal</h1>
+ <p class="hb-lede">Text breaks into pieces that appear one after another. Best for headlines.</p>
+ </header>
+
+ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">1</span>
+ <div><h2 id="hb-watch-title">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div>
+ </div>
+ <div class="stage hb-dots">
+ <div id="text-target" class="splitting" data-mode="words" data-anim="fade-up">Design beyond the obvious</div>
</div>
- <div class="lbl">Animation per unit</div>
- <div class="seg" id="anim-seg">
- <button data-a="fade-up" class="on" aria-label="Fade up">↑Fade</button>
- <button data-a="fade">Fade</button>
- <button data-a="scale">Scale</button>
- <button data-a="rotate">Rotate</button>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop><span>Loop</span></label>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo><span>Slow motion</span></label>
</div>
- <div><div class="lbl" id="stag-lbl">Stagger delay</div>
- <div class="sr"><input type="range" id="stag-sl" aria-labelledby="stag-lbl" min="5" max="100" value="30" step="5"><span class="sv" id="stag-v">30ms</span></div>
+ </section>
+
+ <section class="hb-step hb-try" aria-labelledby="hb-try-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">2</span>
+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and the animation plays again.</p></div>
</div>
- <div><div class="lbl" id="dur-lbl">Duration per unit</div>
- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="100" max="1200" value="500" step="50"><span class="sv" id="dur-v">500ms</span></div>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="mode-lbl">Split into</p>
+ <div class="seg" id="mode-seg" role="group" aria-labelledby="mode-lbl">
+ <button type="button" data-mode="chars" aria-pressed="false">Letters</button>
+ <button type="button" data-mode="words" class="on" aria-pressed="true">Words</button>
+ <button type="button" data-mode="lines" aria-pressed="false">Lines</button>
+ </div>
+ <p class="hb-hint">Letters ripple finely; lines arrive in blocks.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="anim-lbl">How each piece appears</p>
+ <div class="seg" id="anim-seg" role="group" aria-labelledby="anim-lbl">
+ <button type="button" data-anim="fade-up" class="on" aria-pressed="true">Fade up</button>
+ <button type="button" data-anim="fade" aria-pressed="false">Fade</button>
+ <button type="button" data-anim="scale" aria-pressed="false">Grow</button>
+ <button type="button" data-anim="rotate" aria-pressed="false">Flip</button>
+ </div>
+ <p class="hb-hint">The small entrance every piece plays.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="stagger-lbl">Delay between pieces</p>
+ <div class="seg" id="stagger-seg" role="group" aria-labelledby="stagger-lbl">
+ <button type="button" data-stagger="10" aria-pressed="false">Short</button>
+ <button type="button" data-stagger="30" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-stagger="100" aria-pressed="false">Long</button>
+ </div>
+ <p class="hb-hint">Short ripples quickly; long feels deliberate.</p>
+ </div>
</div>
- <div><div class="lbl">Easing</div>
- <select id="ease-sel">
- <option value="linear">Linear</option>
- <option value="ease-out">Ease out</option>
- <option value="cubic-bezier(.2,.7,.3,1)" selected>Smooth</option>
- <option value="cubic-bezier(.34,1.56,.64,1)">Springy</option>
- </select>
+ <details class="hb-options">
+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="speed-lbl">Speed</p>
+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
+ <button type="button" data-ms="800" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="500" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="300" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How long each piece takes to appear.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="feel-lbl">Feel</p>
+ <div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">
+ <button type="button" data-ease="cubic-bezier(.2,.7,.3,1)" class="on" aria-pressed="true">Smooth</button>
+ <button type="button" data-ease="cubic-bezier(.34,1.56,.64,1)" aria-pressed="false">Springy</button>
+ <button type="button" data-ease="linear" aria-pressed="false">Even</button>
+ </div>
+ <p class="hb-hint">Springy goes a little past, then settles.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-setting-name" for="txt-in">Your text</label>
+ <input class="hb-text" type="text" id="txt-in" value="Design beyond the obvious">
+ <p class="hb-hint">Type your own words to see them split.</p>
+ </div>
+ </div>
+ </details>
+ </section>
+
+ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">3</span>
+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
</div>
- <div><div class="lbl">Edit text</div>
- <input type="text" id="txt-in" value="Design beyond the obvious" aria-label="Edit text">
+ <div class="hb-card">
+ <p class="hb-prompt">Add a split-text reveal to [your headline]. Break the text into pieces (characters, words or lines) and animate each piece into view one after another with a short delay between them, so the text flows in as a cascade instead of appearing all at once. Every piece plays the same small entrance, such as fading up from slightly below. Screen readers should still read the text as one normal sentence, not as separate pieces, and the text must not reflow or jump while it animates. If the visitor has reduced motion turned on, show the text immediately. Match the settings listed below.</p>
+ <div class="hb-chips-box" hidden>
+ <p class="hb-chips-title">Your settings</p>
+ <ul class="hb-chips"></ul>
+ </div>
+ <div class="hb-copy-row">
+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
+ </div>
</div>
- <div class="div"></div>
- <label class="tog" for="loop-tog"><input type="checkbox" id="loop-tog" data-hb-skip data-hb-loop><span>Auto-loop</span></label>
- <div class="btn-row">
- <button class="act pri" id="btn-in" data-hb-replay aria-label="Play reveal">Play in</button>
- <button class="act" id="btn-out" aria-label="Hide">Play out</button>
- <button class="act" id="btn-rst" data-hb-reset aria-label="Reset">Reset</button>
+ </section>
+
+ <section class="hb-about" aria-labelledby="hb-what-title">
+ <div class="hb-what">
+ <h2 id="hb-what-title">What it is</h2>
+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
</div>
- </section>
- <div class="hb-take">
- <section class="hb-prompt-box" aria-labelledby="hb-prompt-title">
- <h2 class="hb-label" id="hb-prompt-title">Prompt</h2>
- <p class="hb-prompt">Add a split-text reveal to [your headline]. Break the text into pieces (characters, words or lines) and animate each piece into view one after another with a short delay between them, so the text flows in as a cascade instead of appearing all at once. Every piece plays the same small entrance, such as fading up from slightly below. Screen readers should still read the text as one normal sentence, not as separate pieces, and the text must not reflow or jump while it animates. If the visitor has reduced motion turned on, show the text immediately. Match the settings listed below.</p>
- </section>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Headlines</li><li>Taglines</li><li>Short quotes</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Body text</li><li>Buttons and labels</li></ul>
</div>
- </aside>
+ </section>
+
+ <section class="hb-related" aria-labelledby="hb-related-title" hidden>
+ <h2 id="hb-related-title">Similar animations</h2>
+ <div class="hb-rel-list"></div>
+ </section>
</main>
+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
<script>
const target=document.getElementById('text-target');
- const stEl=document.getElementById('st'),totalEl=document.getElementById('total-time');
- const durSl=document.getElementById('dur-sl'),durV=document.getElementById('dur-v');
- const stagSl=document.getElementById('stag-sl'),stagV=document.getElementById('stag-v');
- const easeSel=document.getElementById('ease-sel'),txtIn=document.getElementById('txt-in');
- const loopTog=document.getElementById('loop-tog');
+ const vars=document.documentElement.style;
+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');
+ const txtIn=document.getElementById('txt-in');
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
- let mode='words',anim='fade-up',dur=500,stagger=30,looping=false,loopTimer=null,animTimer=null;
+ let mode='words',anim='fade-up',ms=500,stagger=30,ease='cubic-bezier(.2,.7,.3,1)',timers=[];
+ function dur(){return slowTog.checked?ms*3:ms}
+ function stag(){return slowTog.checked?stagger*3:stagger}
+ function apply(){
+ vars.setProperty('--dur',dur()+'ms');
+ vars.setProperty('--stagger',stag()+'ms');
+ vars.setProperty('--ease',ease);
+ }
+ // Rebuilds the split pieces from the current mode and text. Runs immediately when Split into or
+ // Your text changes (so the stage never shows a stale split), and again on every play.
function split(){
+ target.classList.remove('in');
const text=txtIn.value||'Design beyond the obvious';
target.dataset.mode=mode;target.dataset.anim=anim;
target.innerHTML='';
if(mode==='chars'){
let unitIdx=0;
[...text].forEach(c=>{
- if(c===' '){target.appendChild(document.createTextNode(' '));return;}
+ if(c===' '){target.appendChild(document.createTextNode(' '));return;}
const s=document.createElement('span');s.className='unit';s.style.setProperty('--i',unitIdx++);
s.textContent=c;target.appendChild(s);
});
@@ -172,44 +221,47 @@
if(mode==='words'&&i<units.length-1)target.appendChild(document.createTextNode(' '));
});
}
- updateTotal();
- }
- function updateTotal(){
- const n=target.querySelectorAll('.unit').length;
- totalEl.textContent=Math.round(n*stagger+dur)+'ms';
}
-
- function _trigger(cls){
- clearTimeout(animTimer);
+ function later(fn,wait){timers.push(setTimeout(fn,wait))}
+ function playLen(){return target.querySelectorAll('.unit').length*stag()+dur()}
+ function revealIn(){
+ // snap back to hidden without a transition so every play reveals the pieces again
+ target.style.setProperty('transition','none','important');
target.classList.remove('in');void target.offsetWidth;
- if(cls==='in')target.classList.add('in');
- stEl.textContent=cls==='in'?'playing in':'playing out';
- const n=target.querySelectorAll('.unit').length;
- animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',n*stagger+dur);
+ target.style.removeProperty('transition');
+ target.classList.add('in');
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
- function reset(){stopLoop();clearTimeout(animTimer);target.classList.remove('in');stEl.textContent='hidden'}
- function playIn(){stopLoop();_trigger('in')}
- function playOut(){stopLoop();_trigger('out')}
- function loop(){_trigger('in');const n=target.querySelectorAll('.unit').length;const t=n*stagger+dur;loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},t+400)},t+800)}
+ // One play reveals the pieces. While Loop is on it then holds, hides them again, waits and plays
+ // again; switching Loop off lets the pieces finish shown. Slow motion stretches the reveal and the
+ // stagger, not the waits.
+ function cycle(){
+ apply();revealIn();
+ if(!loopTog.checked||!motionOk)return;
+ const len=playLen();
+ later(()=>{
+ if(!loopTog.checked)return;
+ target.classList.remove('in');
+ later(cycle,len+400);
+ },len+800);
+ }
+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}
- document.getElementById('btn-in').addEventListener('click',playIn);
- document.getElementById('btn-out').addEventListener('click',playOut);
- document.getElementById('btn-rst').addEventListener('click',reset);
- loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});
- document.querySelectorAll('#mode-seg button').forEach(b=>b.addEventListener('click',()=>{
- document.querySelectorAll('#mode-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- mode=b.dataset.m;reset();split();
- }));
- document.querySelectorAll('#anim-seg button').forEach(b=>b.addEventListener('click',()=>{
- document.querySelectorAll('#anim-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- anim=b.dataset.a;target.dataset.anim=anim;reset();
- }));
- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms');updateTotal()});
- stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms';document.documentElement.style.setProperty('--stagger',stagger+'ms');updateTotal()});
- easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
- txtIn.addEventListener('input',()=>{reset();split()});
- split();
+ document.getElementById('btn-play').addEventListener('click',play);
+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});
+ function choices(id,pick){
+ const buttons=document.querySelectorAll('#'+id+' button');
+ buttons.forEach(b=>b.addEventListener('click',()=>{
+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
+ pick(b.dataset);
+ }));
+ }
+ choices('mode-seg',d=>{mode=d.mode;split()});
+ choices('anim-seg',d=>{anim=d.anim;target.dataset.anim=anim});
+ choices('stagger-seg',d=>{stagger=+d.stagger});
+ choices('speed-seg',d=>{ms=+d.ms});
+ choices('feel-seg',d=>{ease=d.ease});
+ txtIn.addEventListener('input',split);
+ apply();split();
</script>
</body>
</html>
diff --git a/index.html b/index.html
index fb720796..9e4be1ef 100644
--- a/index.html
+++ b/index.html
@@ -918,7 +918,7 @@ const CATS=[
['scale-in','Scale In / Zoom In','Grows from smaller to full size. Best for pop-ups and menus.'],
['clip-path-reveal','Clip-Path Reveal','A growing shape uncovers it while it stays still. Best for images and banners.'],
['curtain-reveal','Curtain Reveal','A colored panel covers it, then slides away. Best for intros and logos.'],
- ['split-text-reveal','Split Text Reveal','Text split into chars, words, or lines — each piece staggers with --index CSS transition-delay.'],
+ ['split-text-reveal','Split Text Reveal','Text breaks into pieces that appear one after another. Best for headlines.'],
['letter-by-letter-stagger','Letter-by-Letter Stagger','CSS transition-delay cascade per letter, or JS typewriter mode with a blinking cursor.'],
['word-by-word-reveal','Word-by-Word Reveal','Words animate sequentially at 80–120ms per word — the readable stagger speed for taglines.'],
['blur-in','Blur In','Fades in while reducing blur — mimics camera focus pulling. Best on single hero elements.'],