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 Word-by-Word Reveal to the guided-steps page

matinf108b69b9322
diff --git a/animations/02-entrance-and-exit/word-by-word-reveal/README.md b/animations/02-entrance-and-exit/word-by-word-reveal/README.md
index a48b7593..8352a5fc 100644
--- a/animations/02-entrance-and-exit/word-by-word-reveal/README.md
+++ b/animations/02-entrance-and-exit/word-by-word-reveal/README.md
@@ -32,17 +32,18 @@ words.forEach((w,wi)=>{
.splitting.in .word{opacity:1;transform:none;filter:none}
```
-The "sentence pauses" option adds `si × 200ms` to the delay for each sentence, inserting a beat between lines. Because the index is stored as `delay/stagger`, the CSS math stays a single `calc()` regardless of whether pauses are on.
+The Pauses between sentences switch adds `si × 200ms` to the delay for each sentence, inserting a beat between lines. Because the index is stored as `delay/stagger`, the CSS math stays a single `calc()` regardless of whether pauses are on.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Per-word delay | 80ms | The reading-speed control; below about 40ms the words blur into one reveal |
-| Per-word animation | Fade up | The entrance each word plays |
-| Duration per word | 450ms | How long each word takes to settle |
-| Easing | Smooth | Springy adds a bounce; Linear feels mechanical |
-| Sentence pauses | off | Adds an extra pause between sentences |
+| Delay between words | Medium | The reading-speed control: short is 40ms, medium 80ms and long 150ms; below about 40ms the words blur into one reveal |
+| How each word appears | Fade up | The entrance each word plays: fade up, fade, grow, blur or flip |
+| Speed | Normal | How long each word takes to settle: slow is 700ms, normal 450ms and fast 270ms |
+| Feel | Smooth | Smooth slows each word into place; Springy adds a bounce; Even feels mechanical |
+| Pauses between sentences | off | Adds an extra pause between sentences |
+| Your text | Three sample sentences | The passage that is revealed, one sentence per line |
## Production notes
- **Whitespace preservation**: keeping a real text node (a literal space) between word spans lets the browser wrap and justify normally, which pure `margin-right` spacing cannot do reliably across fonts.
@@ -53,6 +54,6 @@ The "sentence pauses" option adds `si × 200ms` to the delay for each sentence,
- **Motion One**: `stagger(0.08)` passed as the `delay` option to `animate()`.
## See also
-- [Letter-by-Letter Stagger](../letter-by-letter-stagger/) — the finer-grained sibling, for short headlines
-- [Split-Text Reveal](../split-text-reveal/) — general text-splitting entrance techniques
-- [Fade In / Out](../fade-in-out/) — the base opacity transition each word uses
+- [Letter-by-Letter Stagger](../letter-by-letter-stagger/) — one letter at a time, for short phrases
+- [Split Text Reveal](../split-text-reveal/) — text breaks into letters, words or lines
+- [Fade In / Out](../fade-in-out/) — the whole text fades in at once
diff --git a/animations/02-entrance-and-exit/word-by-word-reveal/index.html b/animations/02-entrance-and-exit/word-by-word-reveal/index.html
index b3a384cd..4388a4f6 100644
--- a/animations/02-entrance-and-exit/word-by-word-reveal/index.html
+++ b/animations/02-entrance-and-exit/word-by-word-reveal/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Word-by-Word Reveal — Animation Handbook</title>
- <meta name="description" content="Words animate sequentially — 80–120ms per word matches comfortable reading speed.">
+ <meta name="description" content="Words appear one after another at a reading pace. Best for quotes and intros.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/word-by-word-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="Word-by-Word Reveal — Animation Handbook">
- <meta property="og:description" content="Words animate sequentially — 80–120ms per word matches comfortable reading speed.">
+ <meta property="og:description" content="Words appear one after another at a reading pace. Best for quotes and intros.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/word-by-word-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="Word-by-Word Reveal — Animation Handbook">
- <meta name="twitter:description" content="Words animate sequentially — 80–120ms per word matches comfortable reading speed.">
+ <meta name="twitter:description" content="Words appear one after another at a reading pace. Best for quotes and intros.">
<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": "Word-by-Word Reveal", "name": "Word-by-Word Reveal", "description": "Words animate sequentially — 80–120ms per word matches comfortable reading speed.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/word-by-word-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, Word-by-Word Reveal"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Word-by-Word Reveal", "name": "Word-by-Word Reveal", "description": "Words appear one after another at a reading pace. Best for quotes and intros.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/word-by-word-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, Word-by-Word 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:450ms;--ease:cubic-bezier(.2,.7,.3,1);--stagger:80ms}
+ :root{--ui-accent:#5fd88a;--dur:450ms;--ease:cubic-bezier(.2,.7,.3,1);--stagger:80ms;--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(16px,2.4vw,22px);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,5vw,56px)}
+ .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(18px,3vw,28px);font-weight:bold;text-align:center;line-height:1.55;max-width:520px}
.word{display:inline-block;margin-right:0.28em;
opacity:0;transition:opacity var(--dur) var(--ease) calc(var(--i)*var(--stagger)),transform var(--dur) var(--ease) calc(var(--i)*var(--stagger)),filter var(--dur) var(--ease) calc(var(--i)*var(--stagger))}
@@ -39,107 +35,163 @@
[data-anim="fade"] .word{transform:none}
.splitting.in .word{opacity:1;transform:none;filter:none}
.sent-break{display:block;height:0.4em}
+ @media(max-width:600px){.stage{min-height:300px}}
@media(prefers-reduced-motion:reduce){.word{transition:opacity 300ms linear!important;transform:none!important;filter:none!important}}
- 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}
- .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}
- textarea{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%;resize:vertical;min-height:60px;line-height:1.5}
- .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%}: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="../letter-by-letter-stagger/" rel="prev" aria-label="Previous: Letter-by-Letter Stagger">‹ <span class="hb-name">Letter-by-Letter Stagger</span></a><a href="../blur-in/" rel="next" aria-label="Next: Blur In"><span class="hb-name">Blur In</span> ›</a></span></nav>
-<main class="hb-view">
- <div class="stage">
- <div id="text-target" class="splitting" data-anim="fade-up"></div>
- </div>
- <aside class="hb-side">
- <header class="hb-head">
- <p class="hb-cat">02.09 · Entrance &amp; Exit</p>
- <h1>Word-by-Word Reveal</h1>
- <p class="hb-lede">Words appear one after another at a comfortable reading pace.</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><div class="lbl" id="stag-lbl">Per-word delay</div>
- <div class="sr"><input type="range" id="stag-sl" aria-labelledby="stag-lbl" min="20" max="200" value="80" step="10"><span class="sv" id="stag-v">80ms</span></div>
+<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="../letter-by-letter-stagger/" rel="prev" aria-label="Previous: Letter-by-Letter Stagger"><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>Letter-by-Letter Stagger</span></a><a href="../blur-in/" rel="next" aria-label="Next: Blur In"><span><span class="hb-dir">Next: </span>Blur In</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.09 · Entrance &amp; Exit</p>
+ <h1>Word-by-Word Reveal</h1>
+ <p class="hb-lede">Words appear one after another at a reading pace. Best for quotes and intros.</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-anim="fade-up"></div>
</div>
- <div><div class="lbl">Per-word animation</div>
- <select id="anim-sel">
- <option value="fade-up" selected>Fade up</option>
- <option value="fade">Fade only</option>
- <option value="scale">Scale in</option>
- <option value="blur">Blur in</option>
- <option value="rotate">Rotate X</option>
- </select>
+ <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="dur-lbl">Duration per word</div>
- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="100" max="1000" value="450" step="50"><span class="sv" id="dur-v">450ms</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">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>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="stagger-lbl">Delay between words</p>
+ <div class="seg" id="stagger-seg" role="group" aria-labelledby="stagger-lbl">
+ <button type="button" data-stagger="40" aria-pressed="false">Short</button>
+ <button type="button" data-stagger="80" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-stagger="150" aria-pressed="false">Long</button>
+ </div>
+ <p class="hb-hint">Medium matches a comfortable reading pace.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="anim-lbl">How each word 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="blur" aria-pressed="false">Blur</button>
+ <button type="button" data-anim="rotate" aria-pressed="false">Flip</button>
+ </div>
+ <p class="hb-hint">The small entrance every word plays.</p>
+ </div>
+ <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="700" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="450" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="270" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How long each word takes to settle.</p>
+ </div>
</div>
- <label class="tog" for="punct-tog"><input type="checkbox" id="punct-tog"><span>Sentence pauses</span></label>
- <div><div class="lbl">Edit text</div>
- <textarea id="txt-in" aria-label="Edit text">We build interfaces that disappear.
+ <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="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 adds a small bounce as each word lands.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Pauses between sentences</span><input class="hb-switch" type="checkbox" role="switch" id="punct-tog"></label>
+ <p class="hb-hint">Waits a little longer before each new sentence.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-setting-name" for="txt-in">Your text</label>
+ <textarea class="hb-text" id="txt-in">We build interfaces that disappear.
Tools that feel inevitable.
Software made with care.</textarea>
+ <p class="hb-hint">Put each sentence on its own line.</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 class="hb-card">
+ <p class="hb-prompt">Add a word-by-word reveal to [the paragraph or quote you want to reveal]. Each word should appear a moment after the one before it, so the text builds up as if it is being spoken; a delay close to the pace people read feels most natural. If pauses between sentences are on, wait a little longer at the end of each sentence before continuing. Keep the delay short enough that nobody waits for text they could already read. The full text must stay readable by screen readers and must not reflow while it appears. If the visitor has reduced motion turned on, show all the text at once. 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 word-by-word reveal to [the paragraph or quote you want to reveal]. Each word should appear a moment after the one before it, at roughly the pace people read, so the text builds up as if it is being spoken. If sentence pauses are on, wait a little longer at the end of each sentence before continuing. Keep the delay short enough that nobody waits for text they could already read. The full text must stay readable by screen readers and must not reflow while it appears. If the visitor has reduced motion turned on, show all the text at once. Match the settings listed below.</p>
- </section>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Quotes</li><li>Short paragraphs</li><li>Captions</li><li>Story sections</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Long articles</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'),animSel=document.getElementById('anim-sel');
+ const vars=document.documentElement.style;
+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');
const punctTog=document.getElementById('punct-tog'),txtIn=document.getElementById('txt-in');
- const loopTog=document.getElementById('loop-tog');
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
- let stagger=80,dur=450,looping=false,loopTimer=null,animTimer=null;
+ let anim='fade-up',ms=450,stagger=80,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 words (and the sentence breaks) from the current text, stagger and sentence-pause
+ // choice. Runs immediately when Delay between words, Pauses between sentences or Your text changes,
+ // so the stage never shows a stale split, and again whenever a play clears the words back to hidden.
+ // --i is stored as delay/stagger using the plain (unmultiplied) stagger value, so slow motion — which
+ // only stretches the CSS --stagger — scales the sentence-pause bonus along with the per-word delay.
function buildWords(){
- target.innerHTML='';target.dataset.anim=animSel.value;
+ target.innerHTML='';target.dataset.anim=anim;
const sentences=(txtIn.value||'').split('\n').filter(Boolean);
- let idx=0,totalWords=0;
+ let idx=0;
sentences.forEach((sent,si)=>{
const words=sent.trim().split(/\s+/).filter(Boolean);
words.forEach((w,wi)=>{
@@ -148,44 +200,56 @@ Software made with care.</textarea>
s.style.setProperty('--i',delay/stagger);
s.textContent=w;target.appendChild(s);
if(wi<words.length-1)target.appendChild(document.createTextNode(' '));
- idx++;totalWords++;
+ idx++;
});
if(si<sentences.length-1){const br=document.createElement('span');br.className='sent-break';target.appendChild(br);}
});
- const extra=punctTog.checked?(sentences.length-1)*200:0;
- totalEl.textContent=Math.round(totalWords*stagger+dur+extra)+'ms';
}
-
- function _trigger(cls){
- clearTimeout(animTimer);target.classList.remove('in');void target.offsetWidth;
- if(cls==='in')target.classList.add('in');
- stEl.textContent=cls==='in'?'playing in':'playing out';
- const words=target.querySelectorAll('.word');
- const maxIdx=Math.max(0,...[...words].map(w=>parseFloat(w.style.getPropertyValue('--i'))||0));
- animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',maxIdx*stagger+dur+200);
+ function later(fn,wait){timers.push(setTimeout(fn,wait))}
+ // The last word's --i times the current --stagger, plus the settle duration: how long a full play takes.
+ function playLen(){
+ const words=[...target.querySelectorAll('.word')];
+ const maxIdx=Math.max(0,...words.map(w=>parseFloat(w.style.getPropertyValue('--i'))||0));
+ return maxIdx*stag()+dur();
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
- function playIn(){stopLoop();_trigger('in')}
- function playOut(){stopLoop();_trigger('out')}
- function loop(){
- _trigger('in');
- const words=target.querySelectorAll('.word');
- const maxIdx=Math.max(0,...[...words].map(w=>parseFloat(w.style.getPropertyValue('--i'))||0));
- const t=maxIdx*stagger+dur;
- loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},t+400)},t+1000);
+ function revealIn(){
+ // snap back to hidden without a transition so every play reveals the words again
+ target.style.setProperty('transition','none','important');
+ target.classList.remove('in');void target.offsetWidth;
+ target.style.removeProperty('transition');
+ target.classList.add('in');
}
+ // One play reveals the words in turn. While Loop is on it then holds, hides them again, waits and
+ // plays again; switching Loop off lets the words finish shown. Slow motion stretches the reveal and
+ // the stagger, not the hold or the wait.
+ 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+1000);
+ }
+ 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',()=>{stopLoop();clearTimeout(animTimer);target.classList.remove('in');stEl.textContent='hidden'});
- loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});
- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms');buildWords()});
- stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms';document.documentElement.style.setProperty('--stagger',stagger+'ms');buildWords()});
- easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
- animSel.addEventListener('change',()=>{target.dataset.anim=animSel.value});
+ 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('stagger-seg',d=>{stagger=+d.stagger;buildWords()});
+ choices('anim-seg',d=>{anim=d.anim;target.dataset.anim=anim});
+ choices('speed-seg',d=>{ms=+d.ms});
+ choices('feel-seg',d=>{ease=d.ease});
punctTog.addEventListener('change',buildWords);
- txtIn.addEventListener('input',()=>{stopLoop();clearTimeout(animTimer);target.classList.remove('in');buildWords();stEl.textContent='hidden'});
- buildWords();
+ txtIn.addEventListener('input',buildWords);
+ apply();buildWords();
</script>
</body>
</html>
diff --git a/index.html b/index.html
index 9f1a0466..557fa49b 100644
--- a/index.html
+++ b/index.html
@@ -920,7 +920,7 @@ const CATS=[
['curtain-reveal','Curtain Reveal','A colored panel covers it, then slides away. Best for intros and logos.'],
['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','A phrase appears letter by letter, or is typed out. Best for short headlines.'],
- ['word-by-word-reveal','Word-by-Word Reveal','Words animate sequentially at 80–120ms per word — the readable stagger speed for taglines.'],
+ ['word-by-word-reveal','Word-by-Word Reveal','Words appear one after another at a reading pace. Best for quotes and intros.'],
['blur-in','Blur In','Fades in while reducing blur — mimics camera focus pulling. Best on single hero elements.'],
['flip-in','Flip In','Rotates from a flat plane into view using CSS 3D perspective — perspective on the parent is the key.'],
['bounce-in','Bounce In','Overshoots final position then springs back — explicit @keyframes waypoints, not easing alone.'],