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.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: move Letter-by-Letter Stagger to the guided-steps page
matinbf6f719ea55a
diff --git a/animations/02-entrance-and-exit/letter-by-letter-stagger/README.md b/animations/02-entrance-and-exit/letter-by-letter-stagger/README.mdindex a427acde..6c74d06b 100644--- a/animations/02-entrance-and-exit/letter-by-letter-stagger/README.md+++ b/animations/02-entrance-and-exit/letter-by-letter-stagger/README.md@@ -38,11 +38,12 @@ Adding the `.done` class flips every letter to its resting state simultaneously;| Parameter | Default | Effect ||-----------|---------|--------|-| Mode | Cascade | Cascade animates every letter in turn; Typewriter types them out behind a cursor |-| Per-letter animation | Fade up | The entrance each letter plays in Cascade mode: fade up, fade, scale or rotate |-| Per-letter delay | 35ms | Gap between letters; higher is slower and more theatrical |-| Duration per letter | 400ms | How long each letter takes to settle |-| Show cursor (typewriter) | on | The blinking cursor in Typewriter mode |+| Style | Cascade | Cascade animates every letter in turn; Typewriter types them out |+| Delay between letters | Medium | The gap between letters: short is 20ms, medium 35ms and long 80ms; higher is slower and more theatrical |+| How each letter appears | Fade up | In Cascade, the entrance each letter plays: fade up, fade, grow or flip |+| Speed | Normal | In Cascade, how long each letter takes to settle: slow is 650ms, normal 400ms and fast 250ms |+| Blinking cursor | on | In Typewriter, a blinking cursor leads the letters |+| Your text | Hello, world. | The phrase that is animated, up to 60 characters |## Production notes- **Accessibility**: split text still reads as separate spans to most screen readers, but wrapping the whole phrase in an `aria-label` on the container and hiding the spans with `aria-hidden` guarantees the label is announced as one string. The demo honors `prefers-reduced-motion` by forcing all letters visible with no transition.@@ -53,6 +54,6 @@ Adding the `.done` class flips every letter to its resting state simultaneously;- **Motion One**: pass an array of elements to `animate()` with a `delay: stagger(0.035)` helper.## See also-- [Word-by-Word Reveal](../word-by-word-reveal/) — the same stagger at word granularity, better for longer text-- [Split-Text Reveal](../split-text-reveal/) — related text-splitting entrance patterns-- [Blur In](../blur-in/) — a per-letter blur makes an effective cascade transform+- [Word-by-Word Reveal](../word-by-word-reveal/) — one word at a time, better for longer text+- [Split Text Reveal](../split-text-reveal/) — text breaks into letters, words or lines+- [Blur In](../blur-in/) — sharpens from a blur as it fades indiff --git a/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html b/animations/02-entrance-and-exit/letter-by-letter-stagger/index.htmlindex 613d681e..31f63854 100644--- a/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html+++ b/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Letter-by-Letter Stagger — Animation Handbook</title>- <meta name="description" content="Cascade: CSS transition-delay per letter. Typewriter: JS sequential reveal with a blinking cursor.">+ <meta name="description" content="A phrase appears letter by letter, or is typed out. Best for short headlines."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/letter-by-letter-stagger/"><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="Letter-by-Letter Stagger — Animation Handbook">- <meta property="og:description" content="Cascade: CSS transition-delay per letter. Typewriter: JS sequential reveal with a blinking cursor.">+ <meta property="og:description" content="A phrase appears letter by letter, or is typed out. Best for short headlines."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/letter-by-letter-stagger/"><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="Letter-by-Letter Stagger — Animation Handbook">- <meta name="twitter:description" content="Cascade: CSS transition-delay per letter. Typewriter: JS sequential reveal with a blinking cursor.">+ <meta name="twitter:description" content="A phrase appears letter by letter, or is typed out. Best for short 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": "Letter-by-Letter Stagger", "name": "Letter-by-Letter Stagger", "description": "Cascade: CSS transition-delay per letter. Typewriter: JS sequential reveal with a blinking cursor.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/letter-by-letter-stagger/", "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, Letter-by-Letter Stagger"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Letter-by-Letter Stagger", "name": "Letter-by-Letter Stagger", "description": "A phrase appears letter by letter, or is typed out. Best for short headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/letter-by-letter-stagger/", "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, Letter-by-Letter Stagger"}</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:400ms;--ease:ease-out;--stagger:35ms}+ :root{--ui-accent:#5fd88a;--dur:400ms;--ease:ease-out;--stagger:35ms;--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,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(26px,5vw,56px);font-weight:bold;text-align:center;line-height:1.2;max-width:560px;word-break:break-word;position:relative}/* cascade mode */.char{display:inline-block}@@ -43,163 +39,229 @@.cursor{display:inline-block;width:3px;height:0.85em;background:var(--ui-accent);vertical-align:text-bottom;margin-left:2px;animation:blink 1s step-end infinite}.cursor.hidden{display:none}@keyframes blink{0%,50%{opacity:1}51%,100%{opacity:0}}+ @media(max-width:600px){.stage{min-height:300px}}@media(prefers-reduced-motion:reduce){.char{transition:none!important;opacity:1!important;transform: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)}- .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;align-items:stretch}.stage{flex:none}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="../split-text-reveal/" rel="prev" aria-label="Previous: Split Text Reveal">‹ <span class="hb-name">Split Text Reveal</span></a><a href="../word-by-word-reveal/" rel="next" aria-label="Next: Word-by-Word Reveal"><span class="hb-name">Word-by-Word Reveal</span> ›</a></span></nav>-<main class="hb-view">- <div class="stage">- <div id="text-target" data-mode="cascade" data-anim="fade-up">Hello, world.</div>- </div>- <aside class="hb-side">- <header class="hb-head">- <p class="hb-cat">02.08 · Entrance & Exit</p>- <h1>Letter-by-Letter Stagger</h1>- <p class="hb-lede">A phrase assembles one letter at a time, as a cascade or a typewriter.</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">Mode</div>- <div class="seg" id="mode-seg">- <button data-m="cascade" class="on">Cascade</button>- <button data-m="typewriter">Typewriter</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="../split-text-reveal/" rel="prev" aria-label="Previous: Split Text 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>Split Text Reveal</span></a><a href="../word-by-word-reveal/" rel="next" aria-label="Next: Word-by-Word Reveal"><span><span class="hb-dir">Next: </span>Word-by-Word Reveal</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.08 · Entrance & Exit</p>+ <h1>Letter-by-Letter Stagger</h1>+ <p class="hb-lede">A phrase appears letter by letter, or is typed out. Best for short 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 id="cascade-opts">- <div class="lbl" style="margin-top:4px">Per-letter animation</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>+ <div class="stage hb-dots">+ <div id="text-target" data-mode="cascade" data-anim="fade-up">Hello, world.</div>+ </div>+ <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">Per-letter delay</div>- <div class="sr"><input type="range" id="stag-sl" aria-labelledby="stag-lbl" min="10" max="120" value="35" step="5"><span class="sv" id="stag-v">35ms</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 class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="style-lbl">Style</p>+ <div class="seg" id="style-seg" role="group" aria-labelledby="style-lbl">+ <button type="button" data-mode="cascade" class="on" aria-pressed="true">Cascade</button>+ <button type="button" data-mode="typewriter" aria-pressed="false">Typewriter</button>+ </div>+ <p class="hb-hint">Cascade animates each letter; Typewriter types them.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="stagger-lbl">Delay between letters</p>+ <div class="seg" id="stagger-seg" role="group" aria-labelledby="stagger-lbl">+ <button type="button" data-stagger="20" aria-pressed="false">Short</button>+ <button type="button" data-stagger="35" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-stagger="80" aria-pressed="false">Long</button>+ </div>+ <p class="hb-hint">Longer delays feel slower and more theatrical.</p>+ </div>+ <div class="hb-setting" id="anim-setting">+ <p class="hb-setting-name" id="anim-lbl">How each letter 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 letter plays.</p>+ </div></div>- <div><div class="lbl" id="dur-lbl">Duration per letter</div>- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="100" max="1000" value="400" step="50"><span class="sv" id="dur-v">400ms</span></div>+ <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" id="speed-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="650" aria-pressed="false">Slow</button>+ <button type="button" data-ms="400" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="250" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How long each letter takes to settle.</p>+ </div>+ <div class="hb-setting" id="cursor-setting" hidden>+ <label class="hb-switch-row"><span>Blinking cursor</span><input class="hb-switch" type="checkbox" role="switch" id="cursor-tog" checked></label>+ <p class="hb-hint">A cursor leads the letters as they are typed.</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="Hello, world." maxlength="60">+ <p class="hb-hint">Short phrases work best, up to 60 characters.</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>- <label class="tog" for="cursor-tog"><input type="checkbox" id="cursor-tog" checked><span>Show cursor (typewriter)</span></label>- <div><div class="lbl">Edit text</div>- <input type="text" id="txt-in" value="Hello, world." aria-label="Edit text" maxlength="60">+ <div class="hb-card">+ <p class="hb-prompt">Add a letter-by-letter entrance to [a short phrase or headline]. In the cascade style, every letter plays a small entrance a moment after the previous one, so the phrase assembles from left to right. In the typewriter style, the letters appear one at a time as if someone is typing, with a blinking cursor when the settings include one. Use it only on short phrases, because long text becomes tedious to wait for. Screen readers should hear the whole phrase once, not letter by letter. If the visitor has reduced motion turned on, show the full phrase 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>- <div class="btn-row">- <button class="act pri" id="btn-play" data-hb-replay aria-label="Replay">Replay</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 letter-by-letter entrance to [a short phrase or headline]. In cascade mode, every letter plays a small entrance a moment after the previous one, so the phrase assembles from left to right. In typewriter mode, the letters appear one at a time behind a blinking cursor, as if someone is typing. Use it only on short phrases, because long text becomes tedious to wait for. Screen readers should hear the whole phrase once, not letter by letter. If the visitor has reduced motion turned on, show the full phrase immediately. Match the settings listed below.</p>- </section>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Short headlines</li><li>Names and logos</li><li>Chat messages</li><li>Loading screens</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Long 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 vars=document.documentElement.style;+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');+ const animSetting=document.getElementById('anim-setting'),speedSetting=document.getElementById('speed-setting'),cursorSetting=document.getElementById('cursor-setting');const cursorTog=document.getElementById('cursor-tog'),txtIn=document.getElementById('txt-in');const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;- let mode='cascade',anim='fade-up',dur=400,stagger=35;- let twTimers=[],animTimer=null;-- function clearTimers(){twTimers.forEach(clearTimeout);twTimers=[];clearTimeout(animTimer)}+ let mode='cascade',anim='fade-up',ms=400,stagger=35,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');+ }+ // Rebuilds the letters (and the cursor, in Typewriter) from the current style, cursor choice and+ // text. Runs immediately when Style, Blinking cursor or Your text changes, so the stage never shows+ // a stale phrase, and again whenever a play clears the letters back to hidden.function buildSpans(){target.classList.remove('done');const text=txtIn.value||'Hello, world.';+ target.dataset.mode=mode;target.dataset.anim=anim;target.innerHTML='';[...text].forEach((c,i)=>{const s=document.createElement('span');s.className='char';s.style.setProperty('--i',i);- s.textContent=c===' '?' ':c;+ s.textContent=c===' '?' ':c;target.appendChild(s);});if(mode==='typewriter'&&cursorTog.checked){const cur=document.createElement('span');cur.className='cursor hidden';cur.id='cursor';target.appendChild(cur);}+ }+ function later(fn,wait){timers.push(setTimeout(fn,wait))}+ function playLen(){const n=target.querySelectorAll('.char').length;- totalEl.textContent=mode==='cascade'?Math.round(n*stagger+dur)+'ms':Math.round(n*stagger)+'ms';+ return mode==='cascade'?n*stag()+dur():n*stag();}-function playCascade(){+ // snap back to hidden without a transition so every play settles in againtarget.classList.remove('done');void target.offsetWidth;- stEl.textContent='playing in';target.classList.add('done');- const n=target.querySelectorAll('.char').length;- animTimer=setTimeout(()=>stEl.textContent='visible',n*stagger+dur);}-function playTypewriter(){- if(!motionOk){target.querySelectorAll('.char').forEach(c=>c.classList.add('visible'));stEl.textContent='visible';return}+ if(!motionOk){+ target.querySelectorAll('.char').forEach(c=>c.classList.add('visible'));+ return;+ }const chars=[...target.querySelectorAll('.char')];const cur=target.querySelector('.cursor');chars.forEach(c=>c.classList.remove('visible'));if(cur)cur.classList.remove('hidden');- stEl.textContent='playing in';- chars.forEach((c,i)=>{twTimers.push(setTimeout(()=>c.classList.add('visible'),i*stagger))});- animTimer=setTimeout(()=>{stEl.textContent='visible';if(cur)cur.classList.add('hidden')},chars.length*stagger);+ chars.forEach((c,i)=>later(()=>c.classList.add('visible'),i*stag()));+ later(()=>{if(cur)cur.classList.add('hidden')},chars.length*stag());}-- function play(){- clearTimers();buildSpans();- requestAnimationFrame(()=>{requestAnimationFrame(()=>{- if(mode==='cascade')playCascade();else playTypewriter();- })});- }- function reset(){- clearTimers();buildSpans();stEl.textContent='hidden';+ // One play reveals the phrase, either as a cascade or typed out. While Loop is on it then holds,+ // clears the letters back to hidden at once with no exit animation, waits and plays again;+ // switching Loop off lets the phrase finish shown. Slow motion stretches the reveal and the+ // per-letter delays, not the hold or the wait.+ function cycle(){+ apply();+ if(mode==='cascade')playCascade();else playTypewriter();+ if(!loopTog.checked||!motionOk)return;+ const len=playLen();+ later(()=>{+ if(!loopTog.checked)return;+ buildSpans();+ later(cycle,400);+ },len+1000);}+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}document.getElementById('btn-play').addEventListener('click',play);- document.getElementById('btn-rst').addEventListener('click',reset);- 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;target.dataset.mode=mode;- document.getElementById('cascade-opts').style.display=mode==='cascade'?'flex':'none';- document.getElementById('cascade-opts').style.flexDirection='column';- document.getElementById('cascade-opts').style.gap='6px';- reset();- }));- 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');reset()});- stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms';document.documentElement.style.setProperty('--stagger',stagger+'ms');reset()});- txtIn.addEventListener('input',reset);cursorTog.addEventListener('change',reset);+ 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('style-seg',d=>{+ mode=d.mode;+ animSetting.hidden=mode!=='cascade';+ speedSetting.hidden=mode!=='cascade';+ cursorSetting.hidden=mode!=='typewriter';+ buildSpans();+ });+ choices('stagger-seg',d=>{stagger=+d.stagger});+ choices('anim-seg',d=>{anim=d.anim;target.dataset.anim=anim});+ choices('speed-seg',d=>{ms=+d.ms});+ cursorTog.addEventListener('change',buildSpans);+ txtIn.addEventListener('input',buildSpans);buildSpans();</script></body>diff --git a/index.html b/index.htmlindex 9e4be1ef..9f1a0466 100644--- a/index.html+++ b/index.html@@ -919,7 +919,7 @@ const CATS=[['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 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.'],+ ['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.'],['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.'],