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 Typewriter Effect to the guided-steps page
matinc8f7749474d9
diff --git a/animations/05-text-typography/typewriter-effect/README.md b/animations/05-text-typography/typewriter-effect/README.mdindex 170b2739..87faa524 100644--- a/animations/05-text-typography/typewriter-effect/README.md+++ b/animations/05-text-typography/typewriter-effect/README.md@@ -1,7 +1,7 @@# Typewriter Effect## What it is-The typewriter effect reveals text character by character, mimicking the cadence of someone typing. A blinking cursor at the insertion point reinforces the illusion. Adding subtle per-character timing variance — random ±20ms jitter — turns a mechanical loop into something that feels genuinely hand-typed, because human typing is never perfectly uniform.+The typewriter effect shows text one character at a time, as if someone is typing it, with a blinking cursor just after the last character. Small random differences in the time between keystrokes make it feel typed by a person rather than a machine, because real typing is never perfectly even.## When to use it- Hero headlines on developer tools, terminal-themed, or hacker-aesthetic sites@@ -68,10 +68,12 @@ function deleteBack(from, to, callback) {## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Speed per char | 50ms | 20ms = fast/robotic; 80–120ms = natural pace; 200ms = slow/deliberate |-| Jitter range | ±20ms | 0 = robotic uniform; ±40ms = very human but erratic |-| Delete speed | ~30ms | Faster than type speed — deleting feels more decisive than typing |-| Cursor style | pipe | Block cursor reads as terminal; pipe reads as text editor; underscore reads as DOS |+| Speed | Normal | The time between keystrokes: slow is 80ms, normal 50ms and fast 30ms; about 80 to 120ms feels like a natural pace |+| Cursor shape | Line | A block reads as a terminal, a line as a text editor, an underscore as an old computer screen |+| Deletes and retypes | off | Types the text, backs up over the last word at about 30ms a character, then types it again with a new ending |+| Types like a person | on | Moves each keystroke up to 20ms earlier or later so the rhythm is uneven, like real typing |+| Cursor color | Pink | The cursor's color; pick one that stands out from the text |+| Your text | Two sample sentences | The text that is typed; short lines work best |## Production notes- **Long text is exhausting**: the typewriter effect works on short hero copy (under ~15 words). A full paragraph typed character-by-character forces users to wait for content they could read instantly. Reserve it for dramatic reveals, not body text.@@ -81,6 +83,6 @@ function deleteBack(from, to, callback) {- **Typed.js**: the canonical library for this effect. Handles multiple strings, backspace, loops, smart backspace (delete only the differing suffix), and HTML tags in strings. Worth using in production rather than rolling your own.## See also-- [Scramble / Glitch Text](../scramble-text/) — a different character-reveal approach: random cycling before settling-- [Rotate Word Carousel](../rotate-word-carousel/) — cycling through words without character-by-character reveal-- [Enter/Exit Typography](../enter-exit-typography/) — phrase-level enter/exit without character-level timing+- [Scramble / Glitch Text](../scramble-text/) — random symbols lock into the real text+- [Rotate Word Carousel](../rotate-word-carousel/) — one word in a sentence keeps changing+- [Enter/Exit Typography](../enter-exit-typography/) — each phrase comes in, holds and leavesdiff --git a/animations/05-text-typography/typewriter-effect/index.html b/animations/05-text-typography/typewriter-effect/index.htmlindex c4d4c39f..36ad351b 100644--- a/animations/05-text-typography/typewriter-effect/index.html+++ b/animations/05-text-typography/typewriter-effect/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Typewriter Effect — Animation Handbook</title>- <meta name="description" content="Characters appear one at a time with a blinking cursor — natural variance makes it feel human.">+ <meta name="description" content="Text types itself out behind a blinking cursor. Best for short taglines."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/typewriter-effect/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,221 +12,245 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Typewriter Effect — Animation Handbook">- <meta property="og:description" content="Characters appear one at a time with a blinking cursor — natural variance makes it feel human.">+ <meta property="og:description" content="Text types itself out behind a blinking cursor. Best for short taglines."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/typewriter-effect/"><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="Typewriter Effect — Animation Handbook">- <meta name="twitter:description" content="Characters appear one at a time with a blinking cursor — natural variance makes it feel human.">+ <meta name="twitter:description" content="Text types itself out behind a blinking cursor. Best for short taglines."><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": "Typewriter Effect", "name": "Typewriter Effect", "description": "Characters appear one at a time with a blinking cursor — natural variance makes it feel human.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/typewriter-effect/", "inLanguage": "en", "articleSection": "Text & Typography", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Text & Typography, Typewriter Effect"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Typewriter Effect", "name": "Typewriter Effect", "description": "Text types itself out behind a blinking cursor. Best for short taglines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/typewriter-effect/", "inLanguage": "en", "articleSection": "Text & Typography", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Text & Typography, Typewriter Effect"}</script><style>- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff6f8b;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--cursor-color:#ff6f8b}+ :root{--ui-accent:#ff6f8b;--cursor-color:#ff6f8b}*,*::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.2vw,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:#04060c;display:flex;align-items:center;justify-content:center;padding:clamp(24px,4vw,48px)}+ .stage{display:flex;align-items:center;justify-content:center;background:#04060c;padding:clamp(24px,4vw,48px)}.type-wrap{width:100%;max-width:520px}- .type-label{font-size:10px;text-transform:uppercase;letter-spacing:2px;color:var(--ui-muted);margin-bottom:14px}- .type-text{font-family:Georgia,'Times New Roman',serif;font-size:clamp(22px,3.5vw,38px);line-height:1.4;color:#fff;min-height:2.8em;word-break:break-word}+ .type-text{font-family:ui-monospace,'SFMono-Regular',Menlo,Consolas,'Liberation Mono',monospace;font-size:clamp(22px,3.5vw,38px);line-height:1.4;color:#fff;min-height:2.8em;word-break:break-word}.cursor{display:inline-block;width:3px;height:1.1em;vertical-align:text-bottom;margin-left:2px;animation:blink 1s step-end infinite}.cursor.block{width:0.55em;height:1.1em;background:var(--cursor-color);opacity:.9}.cursor.pipe{width:2px;background:var(--cursor-color)}.cursor.underscore{width:0.7em;height:2px;vertical-align:baseline;margin-bottom:3px;background:var(--cursor-color)}@keyframes blink{0%,100%{opacity:1}50%{opacity:0}}- .cursor.block,.cursor.pipe,.cursor.underscore{animation:blink 1s step-end infinite}- /* Stats */- .stats{display:flex;gap:16px;font-size:10px;color:var(--ui-muted);margin-top:16px}- .stat-val{color:var(--ui-text)}- /* Panel */- 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)}- .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:44px;text-align:right;color:var(--ui-text)}- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}- textarea{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:72px;line-height:1.5}- .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}- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}input[type=color]{height:44px}}@media(prefers-reduced-motion:reduce){.cursor{animation:none!important;opacity:1!important}}</style>-<style id="ah-inject">-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}-body{padding-top:46px}-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}-.ah-home{color:var(--ah-ink);font-weight:600}-.ah-actions{display:flex;align-items:center;gap:2px}-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}-.ah-copied{color:var(--ah-accent)!important}-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}-@media print{.ah-bar{display:none}body{padding-top:0}}-</style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">+ <script src="../../../assets/js/demo-page.js?v=3" defer></script></head>-<body>-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../kinetic-typography/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../scramble-text/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/05-text-typography/typewriter-effect/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Typewriter Effect</h1>- <p>Characters appear one at a time with a blinking cursor — natural variance makes it feel human.</p>-</header>-<div class="layout">- <div class="stage">- <div class="type-wrap">- <div class="type-label">Typing…</div>- <div class="type-text" id="type-out" aria-live="polite"></div>- <div class="stats">- <span>Speed: <span class="stat-val" id="stat-speed">50ms</span></span>- <span>Chars: <span class="stat-val" id="stat-chars">0</span></span>+<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="../kinetic-typography/" rel="prev" aria-label="Previous: Kinetic Typography"><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>Kinetic Typography</span></a><a href="../scramble-text/" rel="next" aria-label="Next: Scramble / Glitch Text"><span><span class="hb-dir">Next: </span>Scramble / Glitch Text</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">05.02 · Text & Typography</p>+ <h1>Typewriter Effect</h1>+ <p class="hb-lede">Text types itself out behind a blinking cursor. Best for short taglines.</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 hb-grow">+ <div class="type-wrap">+ <div class="type-text" id="type-out" aria-live="polite"></div>+ </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 autocomplete="off"><span>Loop</span></label>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>+ </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="speed-lbl">Speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-ms="80" aria-pressed="false">Slow</button>+ <button type="button" data-ms="50" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="30" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">The time between keystrokes.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="cursor-lbl">Cursor shape</p>+ <div class="seg" id="cursor-seg" role="group" aria-labelledby="cursor-lbl">+ <button type="button" data-shape="pipe" class="on" aria-pressed="true">Line</button>+ <button type="button" data-shape="block" aria-pressed="false">Block</button>+ <button type="button" data-shape="underscore" aria-pressed="false">Underscore</button>+ </div>+ <p class="hb-hint">Block looks like a terminal, line like a text editor.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Deletes and retypes</span><input class="hb-switch" type="checkbox" role="switch" id="retype-tog" autocomplete="off"></label>+ <p class="hb-hint">Backs up over the last word and types a new ending.</p>+ </div>+ </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">+ <label class="hb-switch-row"><span>Types like a person</span><input class="hb-switch" type="checkbox" role="switch" id="jitter-tog" checked autocomplete="off"></label>+ <p class="hb-hint">Small random pauses make it feel less mechanical.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="cursor-color-lbl">Cursor color</p>+ <div class="swatches" id="cursor-color-sw" role="group" aria-labelledby="cursor-color-lbl">+ <button type="button" class="on" aria-pressed="true" aria-label="Pink" data-c="#ff6f8b" style="background:#ff6f8b"></button>+ <button type="button" aria-pressed="false" aria-label="White" data-c="#f4f4f2" style="background:#f4f4f2"></button>+ <button type="button" aria-pressed="false" aria-label="Blue" data-c="#58a6ff" style="background:#58a6ff"></button>+ <button type="button" aria-pressed="false" aria-label="Purple" data-c="#d2a8ff" style="background:#d2a8ff"></button>+ <button type="button" aria-pressed="false" aria-label="Green" data-c="#56d364" style="background:#56d364"></button>+ <button type="button" aria-pressed="false" aria-label="Orange" data-c="#ffa657" style="background:#ffa657"></button>+ </div>+ <p class="hb-hint">Pick a color that stands out from the text.</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="Typography is the art and craft of arranging type. Good type communicates before it decorates." autocomplete="off">+ <p class="hb-hint">Short lines work best; long text is slow to wait for.</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 typewriter effect to [your tagline or short text]. The text should appear one character at a time, as if someone is typing it, with a blinking cursor always just after the last character. Unless the settings turn it off, vary the time between keystrokes slightly so it feels typed by a person rather than a machine. When the settings include it, back up over the last word and type a new ending. Keep it to short text, because long text is slow to wait for. Screen readers should hear the full text once, not each character. If the visitor has reduced motion turned on, show the full 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>- <aside>- <p class="note">Uniform timing feels mechanical. Random jitter (±20ms per char) makes the typewriter feel alive — like a human pausing between keystrokes.</p>- <div class="lbl">Typing Speed</div>- <div class="sr"><input type="range" id="spd-sl" min="20" max="200" value="50" step="5"><span class="sv" id="spd-v">50ms</span></div>- <div class="lbl">Cursor Style</div>- <select id="cursor-sel">- <option value="pipe" selected>Pipe |</option>- <option value="block">Block ▌</option>- <option value="underscore">Underscore _</option>- </select>- <div class="lbl">Cursor Color</div>- <input type="color" id="cursor-color" value="#ff6f8b" aria-label="Cursor color">- <label class="tog"><input type="checkbox" id="jitter-tog" checked><span>Natural variance (±20ms)</span></label>- <label class="tog"><input type="checkbox" id="delete-tog"><span>Backspace + retype</span></label>- <div class="div"></div>- <div class="lbl">Text</div>- <textarea id="text-inp">Typography is the art and craft of arranging type. Good type communicates before it decorates.</textarea>- <button class="rst" id="replay-btn">↺ Replay</button>- <label class="tog"><input type="checkbox" id="loop-tog"><span>Auto-loop</span></label>- </aside>-</div>+ </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>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Taglines</li><li>Chat messages</li><li>Terminal screens</li><li>Short intros</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Long text</li><li>Buttons and labels</li></ul>+ </div>+ </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 typeOut=document.getElementById('type-out');- const statSpeed=document.getElementById('stat-speed');- const statChars=document.getElementById('stat-chars');- let timer=null,running=false;+ const vars=document.documentElement.style;+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');+ const retypeTog=document.getElementById('retype-tog'),jitterTog=document.getElementById('jitter-tog');+ const txtIn=document.getElementById('txt-in');+ const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;+ const DEFAULT_TEXT='Typography is the art and craft of arranging type. Good type communicates before it decorates.';+ let spd=50,shape='pipe',cursor=null,timers=[];+ function later(fn,wait){timers.push(setTimeout(fn,wait))}+ function mul(){return slowTog.checked?3:1}+ // Slow motion stretches every per-character delay after the person-like variation is added.+ function jitter(base){+ const varied=jitterTog.checked?base+Math.round((Math.random()-0.5)*40):base;+ return varied*mul();+ }function makeCursor(){const c=document.createElement('span');- c.className='cursor '+document.getElementById('cursor-sel').value;+ c.className='cursor '+shape;c.setAttribute('aria-hidden','true');return c;}-- function getSpeed(){return +document.getElementById('spd-sl').value}- function jitter(base){- if(!document.getElementById('jitter-tog').checked)return base;- return base+Math.round((Math.random()-0.5)*40);+ function render(shown){+ typeOut.textContent=shown;+ typeOut.appendChild(cursor);}- function type(text,done){- if(timer)clearTimeout(timer);- running=true;+ function typeChars(text,done){let i=0;- typeOut.innerHTML='';- const cursor=makeCursor();- typeOut.appendChild(cursor);-- function tick(){- const spd=getSpeed();- if(i<=text.length){- typeOut.firstChild?.remove?.();- typeOut.insertBefore(document.createTextNode(text.substring(0,i)),null);- typeOut.appendChild(cursor);- statChars.textContent=i;- statSpeed.textContent=spd+'ms';- i++;- timer=setTimeout(tick,jitter(spd));- }else{running=false;done?.();}- }- tick();+ (function tick(){+ render(text.slice(0,i));+ if(i<text.length){i++;later(tick,jitter(spd));}+ else done();+ })();}-- function deleteAndRetype(text){- // Type full text, delete last word, retype it differently+ function deleteChars(text){const words=text.trim().split(' ');const deleteFrom=Math.max(text.length-words[words.length-1].length-1,Math.floor(text.length*0.6));- type(text,()=>{- running=true;- let i=text.length;- function del(){- if(i>deleteFrom){- typeOut.firstChild?.nodeType===3&&(typeOut.firstChild.textContent=text.substring(0,--i));- statChars.textContent=i;- timer=setTimeout(del,jitter(30));- }else{- const rest=text.substring(deleteFrom)+' — always.';- let j=deleteFrom;- function retype(){- if(j<=rest.length+deleteFrom){- typeOut.firstChild?.nodeType===3&&(typeOut.firstChild.textContent=(text.substring(0,deleteFrom)+rest.substring(0,j-deleteFrom)));- statChars.textContent=j;- j++;timer=setTimeout(retype,jitter(getSpeed()));- }else{running=false;afterType();}- }- retype();- }- }- timer=setTimeout(del,500);- });+ let i=text.length;+ (function del(){+ if(i>deleteFrom){i--;render(text.slice(0,i));later(del,jitter(30));}+ else retypeChars(text,deleteFrom);+ })();}-- const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');- function start(){- const text=document.getElementById('text-inp').value;- if(reduceMotion.matches){- // No per-character loop: show the finished line at once.- if(timer)clearTimeout(timer);running=false;- typeOut.textContent=text;typeOut.appendChild(makeCursor());- statChars.textContent=text.length;statSpeed.textContent=getSpeed()+'ms';- return;- }- if(document.getElementById('delete-tog').checked){- deleteAndRetype(text);- }else{- type(text,()=>afterType());- }+ function retypeChars(text,deleteFrom){+ const rest=text.slice(deleteFrom)+' — always.';+ let j=0;+ (function step(){+ render(text.slice(0,deleteFrom)+rest.slice(0,j));+ if(j<rest.length){j++;later(step,jitter(spd));}+ else afterType();+ })();}-function afterType(){- if(document.getElementById('loop-tog').checked)timer=setTimeout(()=>{if(document.getElementById('loop-tog').checked)start()},1200);+ later(()=>{+ if(!loopTog.checked||!motionOk)return;+ cycle();+ },1200);}- document.getElementById('cursor-sel').addEventListener('change',e=>{+ // One play types the text from the start. With Deletes and retypes on, it then waits, backs up over the+ // last word and types a new ending. While Loop is on, the finished text holds 1200ms; whether the play+ // then starts again is decided right after that hold, from Loop's value at that moment, so switching Loop+ // off during the hold still leaves the text shown. Reduced motion shows the full text at once and stops.+ function cycle(){+ const text=txtIn.value||DEFAULT_TEXT;+ cursor=makeCursor();+ if(!motionOk){render(text);return;}+ typeChars(text,()=>{+ if(retypeTog.checked)later(()=>deleteChars(text),500);+ else afterType();+ });+ }+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}++ 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('speed-seg',d=>{spd=+d.ms});+ choices('cursor-seg',d=>{+ shape=d.shape;const c=typeOut.querySelector('.cursor');- if(c)c.className='cursor '+e.target.value;- });- document.getElementById('cursor-color').addEventListener('input',e=>{- document.documentElement.style.setProperty('--cursor-color',e.target.value);+ if(c)c.className='cursor '+shape;});- document.getElementById('spd-sl').addEventListener('input',e=>{- document.getElementById('spd-v').textContent=e.target.value+'ms';- if(!running)statSpeed.textContent=e.target.value+'ms';- });- document.getElementById('loop-tog').addEventListener('change',e=>{- if(e.target.checked&&!running)start();- });- document.getElementById('replay-btn').addEventListener('click',()=>{- if(timer)clearTimeout(timer);running=false;start();- });-- start();+ choices('cursor-color-sw',d=>{vars.setProperty('--cursor-color',d.c)});</script>-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script></body></html>diff --git a/index.html b/index.htmlindex e50d67ea..f1a52b41 100644--- a/index.html+++ b/index.html@@ -988,7 +988,7 @@ const CATS=[folder:'animations/05-text-typography',entries:[['kinetic-typography','Kinetic Typography','Words arrive and leave one by one, each moving its own way. Best for intros.'],- ['typewriter-effect','Typewriter Effect','Characters appear one at a time with a blinking cursor — natural timing variance makes it feel human.'],+ ['typewriter-effect','Typewriter Effect','Text types itself out behind a blinking cursor. Best for short taglines.'],['scramble-text','Scramble / Glitch Text','Random symbols lock into the real text, left to right. Best for tech headlines.'],['variable-font-morph','Variable Font Morph','CSS font-variation-settings animates weight, slant, and casual axes of a variable font.'],['text-clip-path-reveal','Text Clip-Path Reveal','Each line of a headline is uncovered in turn. Best for big headlines.'],