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 Scramble / Glitch Text to the guided-steps page

matin3960761e627b
diff --git a/animations/05-text-typography/scramble-text/README.md b/animations/05-text-typography/scramble-text/README.md
index 118be801..6e39706c 100644
--- a/animations/05-text-typography/scramble-text/README.md
+++ b/animations/05-text-typography/scramble-text/README.md
@@ -1,7 +1,7 @@
# Scramble / Glitch Text
## What it is
-Scramble text (also called glitch text or decode text) cycles each character through random symbols before "locking" to its true value. Characters settle sequentially from left to right, so the word is progressively decoded — the first character locks first, making the reveal directional and readable. The effect evokes decryption, hacking, and sci-fi terminal aesthetics.
+Scramble text shows every letter as a random character that keeps changing, then locks each one into the real letter. The letters lock one after another from left to right, so the text becomes readable bit by bit, as if a hidden message is being decoded. The random characters can be symbols, letters of the alphabet, numbers, Japanese characters or a mix.
## When to use it
- Tech products, cybersecurity tools, and developer-facing sites
@@ -15,32 +15,38 @@ Each character of the target string gets its own `<span>`. A `setInterval` loop
```js
function scramble(el, targetText) {
const chars = '!@#$%^&*<>{}[]|/\\?=+-_~`';
- const locked = new Array(targetText.length).fill(false);
let lockedCount = 0;
- // Build one span per character
- const spans = [...targetText].map((c, i) => {
- if (c === ' ') { el.appendChild(document.createTextNode(' ')); return null; }
- const s = document.createElement('span');
- s.textContent = chars[Math.floor(Math.random() * chars.length)];
- el.appendChild(s);
- return s;
+ // One span per letter; each word's letters sit in one span.unit-word, which keeps the word on one line
+ const spans = [];
+ targetText.split(' ').filter(Boolean).forEach((word, wi, words) => {
+ const w = document.createElement('span');
+ w.className = 'unit-word';
+ [...word].forEach(c => {
+ const s = document.createElement('span');
+ s.dataset.char = c; // the letter it locks to
+ s.textContent = chars[Math.floor(Math.random() * chars.length)];
+ w.appendChild(s);
+ spans.push(s);
+ });
+ el.appendChild(w);
+ if (wi < words.length - 1) el.appendChild(document.createTextNode(' '));
});
+ const locked = new Array(spans.length).fill(false);
// Settle each character after a staggered delay
spans.forEach((s, i) => {
- if (!s) return;
setTimeout(() => {
- s.textContent = targetText[i];
+ s.textContent = s.dataset.char;
locked[i] = true;
- if (++lockedCount === spans.filter(Boolean).length) onDone();
+ if (++lockedCount === spans.length) onDone();
}, settleDelay * i + settleDelay);
});
// Cycle random chars on unlocked positions
const interval = setInterval(() => {
spans.forEach((s, i) => {
- if (s && !locked[i]) s.textContent = chars[Math.floor(Math.random() * chars.length)];
+ if (!locked[i]) s.textContent = chars[Math.floor(Math.random() * chars.length)];
});
}, cycleMs);
@@ -52,10 +58,10 @@ function scramble(el, targetText) {
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Cycle speed | 40ms | How fast random chars swap — faster = more chaotic; slower = more legible |
-| Settle delay per char | 70ms | Gap between each character locking — controls how "fast" the decode reads left-to-right |
-| Character set | Symbols | Symbols feel hacker; katakana (Matrix-style) feels cinematic; alphabetic feels more like autocorrect |
-| Total duration | auto | `settleDelay × charCount` — adjust settle delay to control total animation length |
+| Random characters | Symbols | What the letters flicker through: symbols look like hacking, Japanese characters look like the falling code in science-fiction films, and the alphabet or numbers look like a password being cracked |
+| Delay between letters | Medium | The wait between one letter locking and the next: short is 40ms, medium 70ms and long 120ms; it sets how fast the decoding travels |
+| Flicker speed | Normal | How often the random characters change: slow every 65ms, normal every 40ms and fast every 25ms; faster looks more chaotic |
+| Your text | DECODE THE MESSAGE | The text that is decoded, shown in capitals |
## Production notes
- **Left-to-right settle order**: characters settle in reading order so the word becomes readable progressively, not all at once. Random or simultaneous settling is harder to read and loses the "decoding" narrative.
@@ -66,6 +72,6 @@ function scramble(el, targetText) {
- **`aria-label` pattern**: set `aria-label` to the final decoded text at the start so screen readers announce the correct content, not the scrambled intermediate state.
## See also
-- [Typewriter Effect](../typewriter-effect/) — character-by-character reveal with natural typing rhythm
-- [Kinetic Typography](../kinetic-typography/) — phrase-level motion that could use scramble as one of its enter techniques
-- [Text Morphing](../text-morphing/) — word-to-word character transition, a smoother alternative
+- [Typewriter Effect](../typewriter-effect/) — text typed one character at a time
+- [Kinetic Typography](../kinetic-typography/) — words that each move in their own way
+- [Text Morphing](../text-morphing/) — one word changes into the next, letter by letter
diff --git a/animations/05-text-typography/scramble-text/index.html b/animations/05-text-typography/scramble-text/index.html
index e376ca99..20af0b4e 100644
--- a/animations/05-text-typography/scramble-text/index.html
+++ b/animations/05-text-typography/scramble-text/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scramble / Glitch Text — Animation Handbook</title>
- <meta name="description" content="Characters cycle through random symbols before locking to their true value — decryption aesthetic.">
+ <meta name="description" content="Random symbols lock into the real text, left to right. Best for tech headlines.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/scramble-text/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,199 +12,236 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Scramble / Glitch Text — Animation Handbook">
- <meta property="og:description" content="Characters cycle through random symbols before locking to their true value — decryption aesthetic.">
+ <meta property="og:description" content="Random symbols lock into the real text, left to right. Best for tech headlines.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/scramble-text/">
<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="Scramble / Glitch Text — Animation Handbook">
- <meta name="twitter:description" content="Characters cycle through random symbols before locking to their true value — decryption aesthetic.">
+ <meta name="twitter:description" content="Random symbols lock into the real text, left to right. Best for tech 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": "Scramble / Glitch Text", "name": "Scramble / Glitch Text", "description": "Characters cycle through random symbols before locking to their true value — decryption aesthetic.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/scramble-text/", "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, Scramble / Glitch Text"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Scramble / Glitch Text", "name": "Scramble / Glitch Text", "description": "Random symbols lock into the real text, left to right. Best for tech headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/scramble-text/", "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, Scramble / Glitch Text"}</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}
+ :root{--ui-accent:#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;flex-direction:column;align-items:center;justify-content:center;gap:32px;padding:32px}
- .scramble-wrap{width:100%;max-width:520px}
- .scramble-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted);margin-bottom:12px}
- .scramble-text{font-family:Georgia,'Times New Roman',serif;font-size:clamp(28px,5vw,60px);letter-spacing:0.04em;line-height:1.2;color:#fff;min-height:1.4em;word-break:break-all}
+ .stage{display:flex;align-items:center;justify-content:center;background:#04060c;padding:clamp(20px,4vw,48px)}
+ .scramble-text{width:100%;max-width:720px;min-height:1.4em;font-size:clamp(28px,5vw,60px);font-weight:700;letter-spacing:0.04em;line-height:1.2;color:#fff;text-align:center}
.scramble-text .char{display:inline-block;transition:color 60ms}
.scramble-text .char.locked{color:#fff}
- .scramble-text .char.scrambling{color:#4a7a4a}
- .scramble-text .sp{display:inline-block;width:0.3em}
- /* Status */
- .status-bar{width:100%;max-width:520px;display:flex;gap:16px;font-size:10px;color:var(--ui-muted)}
- .sv{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}
- .sval{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}
- input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
- input[type=text]:focus{border-color:var(--ui-accent)}
- 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)}}
- .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}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}}
+ .scramble-text .char.scrambling{color:#5f9a5f}
+ /* Letters mode: the letters of one word sit in one box that never breaks */
+ .unit-word{display:inline-block;white-space:nowrap}
@media(prefers-reduced-motion:reduce){.scramble-text .char{transition:none!important;color:#fff!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="../typewriter-effect/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../variable-font-morph/" 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/scramble-text/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Scramble / Glitch Text</h1>
- <p>Characters cycle through random symbols before locking to their true value — decryption aesthetic.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <div class="scramble-wrap">
- <div class="scramble-label">Decoding…</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="../typewriter-effect/" rel="prev" aria-label="Previous: Typewriter Effect"><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>Typewriter Effect</span></a><a href="../variable-font-morph/" rel="next" aria-label="Next: Variable Font Morph"><span><span class="hb-dir">Next: </span>Variable Font Morph</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.03 · Text &amp; Typography</p>
+ <h1>Scramble / Glitch Text</h1>
+ <p class="hb-lede">Random symbols lock into the real text, left to right. Best for tech 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 hb-grow">
<div class="scramble-text" id="scramble-out" aria-live="polite" aria-label="Scrambling text"></div>
</div>
- <div class="status-bar">
- <span>Locked: <span class="sv" id="locked-ct">0</span></span>
- <span>Remaining: <span class="sv" id="remain-ct">0</span></span>
- <span>Cycle: <span class="sv" id="cycle-ct">0ms</span></span>
+ <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>
- </div>
- <aside>
- <p class="note">Scramble effects evoke decryption and sci-fi interfaces. Characters settle left-to-right so the word is progressively readable — not all at once.</p>
- <div class="lbl">Cycle Speed</div>
- <div class="sr"><input type="range" id="cyc-sl" min="20" max="100" value="40" step="5"><span class="sval" id="cyc-v">40ms</span></div>
- <div class="lbl">Settle Delay per Char</div>
- <div class="sr"><input type="range" id="settle-sl" min="30" max="200" value="70" step="10"><span class="sval" id="settle-v">70ms</span></div>
- <div class="lbl">Character Set</div>
- <select id="charset-sel">
- <option value="alpha">Alphabetic</option>
- <option value="symbols" selected>Symbols</option>
- <option value="numeric">Numeric</option>
- <option value="matrix">Matrix (katakana)</option>
- <option value="all">All mixed</option>
- </select>
- <div class="div"></div>
- <div class="lbl">Text</div>
- <input type="text" id="text-inp" value="DECODE THE MESSAGE">
- <button class="rst" id="replay-btn">↺ Replay</button>
- <label class="tog"><input type="checkbox" id="loop-tog"><span>Auto-loop</span></label>
- </aside>
-</div>
-<script>
-const CHARSETS={
- alpha:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
- symbols:'!@#$%^&*<>{}[]|/\\?=+-_~`',
- numeric:'0123456789',
- matrix:'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン',
- all:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*<>{}[]'
-};
-let cycleTimer=null,cycleFn=null,running=false,timers=[];
-const later=(fn,ms)=>timers.push(setTimeout(fn,ms));
-const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');
-const out=document.getElementById('scramble-out');
-const lockedCt=document.getElementById('locked-ct');
-const remainCt=document.getElementById('remain-ct');
-const cycleCt=document.getElementById('cycle-ct');
-const charsetSel=document.getElementById('charset-sel');
-const loopTog=document.getElementById('loop-tog');
+ </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="charset-lbl">Random characters</p>
+ <div class="seg" id="charset-seg" role="group" aria-labelledby="charset-lbl">
+ <button type="button" data-charset="alpha" aria-pressed="false">Alphabet</button>
+ <button type="button" data-charset="symbols" class="on" aria-pressed="true">Symbols</button>
+ <button type="button" data-charset="numeric" aria-pressed="false">Numbers</button>
+ <button type="button" data-charset="matrix" aria-pressed="false">Japanese</button>
+ <button type="button" data-charset="all" aria-pressed="false">Mixed</button>
+ </div>
+ <p class="hb-hint">What the letters flicker through before they lock.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="delay-lbl">Delay between letters</p>
+ <div class="seg" id="delay-seg" role="group" aria-labelledby="delay-lbl">
+ <button type="button" data-ms="40" aria-pressed="false">Short</button>
+ <button type="button" data-ms="70" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-ms="120" aria-pressed="false">Long</button>
+ </div>
+ <p class="hb-hint">The wait before each next letter locks into place.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="flicker-lbl">Flicker speed</p>
+ <div class="seg" id="flicker-seg" role="group" aria-labelledby="flicker-lbl">
+ <button type="button" data-ms="65" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="40" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="25" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">Fast looks chaotic; slow lets you see each symbol.</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-setting-name" for="txt-in">Your text</label>
+ <input class="hb-text" type="text" id="txt-in" value="DECODE THE MESSAGE" autocomplete="off">
+ <p class="hb-hint">Short phrases work best. Letters show in capitals.</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 scramble effect to [your headline or short phrase]. Each letter should start as a random character and keep flickering through random characters until it locks into the real letter. Lock the letters in reading order, from left to right, so the text becomes readable bit by bit, as if it is being decoded. Capital letters scramble most cleanly. Screen readers should hear the final text once, never the random characters. If the visitor has reduced motion turned on, show the final 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>
+ </section>
-function randChar(charset){return charset[Math.floor(Math.random()*charset.length)]}
+ <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>Tech headlines</li><li>Loading screens</li><li>Game titles</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Long text</li><li>Calm brands</li></ul>
+ </div>
+ </section>
-function scramble(){
- // Kill every timer from the previous run so a replay never inherits stale settles, clears or loop chains
- clearInterval(cycleTimer);cycleTimer=null;
- timers.forEach(clearTimeout);timers=[];
- running=true;
- const text=document.getElementById('text-inp').value.toUpperCase();
- const charset=CHARSETS[charsetSel.value];
- const cycleMs=+document.getElementById('cyc-sl').value;
- const settleMs=+document.getElementById('settle-sl').value;
- const reduce=reduceMotion.matches;
- cycleCt.textContent=cycleMs+'ms';
+ <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 CHARSETS={
+ alpha:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
+ symbols:'!@#$%^&*<>{}[]|/\\?=+-_~`',
+ numeric:'0123456789',
+ matrix:'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン',
+ all:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*<>{}[]'
+ };
+ const out=document.getElementById('scramble-out');
+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');
+ const txtIn=document.getElementById('txt-in');
+ const reduceMotion=window.matchMedia('(prefers-reduced-motion:reduce)');
+ let charset='symbols',settleMs=70,cycleMs=40,timers=[],cycleTimer=null,cycleFn=null;
- // Build span per char
- out.innerHTML='';
- const spans=[];
- text.split('').forEach((c,i)=>{
- if(c===' '){const sp=document.createElement('span');sp.className='sp';sp.setAttribute('aria-hidden','true');out.appendChild(sp);spans.push(null);return;}
- const s=document.createElement('span');s.className=reduce?'char locked':'char scrambling';s.textContent=reduce?text[i]:randChar(charset);out.appendChild(s);spans.push(s);
- });
- const total=spans.filter(Boolean).length;
+ function randChar(cs){return cs[Math.floor(Math.random()*cs.length)]}
+ function settleDur(){return slowTog.checked?settleMs*3:settleMs}
+ function cycleDur(){return slowTog.checked?cycleMs*3:cycleMs}
+ function later(fn,wait){timers.push(setTimeout(fn,wait))}
- // Reduced motion (or nothing to decode): show the decoded text immediately, no cycling
- if(reduce||!total){
- out.setAttribute('aria-label',text);lockedCt.textContent=total;remainCt.textContent='0';running=false;return;
- }
- out.setAttribute('aria-label','Loading: '+text);
+ // Rebuilds the text scrambled and locks each letter in turn, left to right (spaces take no step).
+ // While Loop is on, the text holds 1200ms once fully decoded, then scrambles again; switching Loop
+ // off lets it finish decoded. Slow motion stretches the per-letter delay and the flicker, not the hold.
+ function cycle(){
+ const text=(txtIn.value||'DECODE THE MESSAGE').toUpperCase();
+ const reduce=reduceMotion.matches;
- const locked=new Array(text.length).fill(false);
- let lockedCount=0;
+ out.innerHTML='';
+ // One span per letter; each word's letters sit in one span.unit-word, which keeps the word on one line
+ const spans=[];
+ text.split(' ').filter(Boolean).forEach((word,wi,words)=>{
+ const w=document.createElement('span');
+ w.className='unit-word';
+ [...word].forEach(c=>{
+ const s=document.createElement('span');
+ s.className=reduce?'char locked':'char scrambling';
+ s.dataset.char=c; // the letter it locks to
+ s.textContent=reduce?c:randChar(CHARSETS[charset]);
+ w.appendChild(s);
+ spans.push(s);
+ });
+ out.appendChild(w);
+ if(wi<words.length-1)out.appendChild(document.createTextNode(' '));
+ });
+ const total=spans.length;
- // Settle each char after staggered delay
- spans.forEach((s,i)=>{
- if(!s)return;
- later(()=>{
- s.textContent=text[i];s.classList.remove('scrambling');s.classList.add('locked');
- locked[i]=true;lockedCount++;
- lockedCt.textContent=lockedCount;
- remainCt.textContent=total-lockedCount;
- if(lockedCount===total){
- clearInterval(cycleTimer);cycleTimer=null;
- running=false;out.setAttribute('aria-label',text);
- // Re-check the toggle when the timer fires so unchecking mid-gap cancels the next run
- if(loopTog.checked)later(()=>{if(loopTog.checked)scramble()},1200);
- }
- },settleMs*i+settleMs);
- });
+ // Reduced motion (or nothing to decode): show the decoded text immediately, no flicker
+ if(reduce||!total){
+ out.setAttribute('aria-label',text);
+ return;
+ }
+ out.setAttribute('aria-label','Loading: '+text);
- // Cycle random chars on unlocked positions; charset is read per tick so the select applies live
- cycleFn=()=>{const cs=CHARSETS[charsetSel.value];spans.forEach((s,i)=>{if(s&&!locked[i])s.textContent=randChar(cs);});};
- cycleTimer=setInterval(cycleFn,cycleMs);
+ const locked=new Array(total).fill(false);
+ let lockedCount=0;
- const totalTime=settleMs*total+settleMs;
- const thisTimer=cycleTimer;
- later(()=>{if(cycleTimer===thisTimer){clearInterval(cycleTimer);cycleTimer=null;}},totalTime+cycleMs*2);
+ // Settle each letter after its staggered delay
+ spans.forEach((s,i)=>{
+ later(()=>{
+ s.textContent=s.dataset.char;s.classList.remove('scrambling');s.classList.add('locked');
+ locked[i]=true;lockedCount++;
+ if(lockedCount===total){
+ clearInterval(cycleTimer);cycleTimer=null;
+ out.setAttribute('aria-label',text);
+ if(!loopTog.checked)return;
+ later(cycle,1200);
+ }
+ },settleDur()*i+settleDur());
+ });
- remainCt.textContent=total;lockedCt.textContent='0';
-}
+ // Cycle random chars on unlocked letters; charset is read per tick so a change applies live
+ cycleFn=()=>{const cs=CHARSETS[charset];spans.forEach((s,i)=>{if(!locked[i])s.textContent=randChar(cs);});};
+ cycleTimer=setInterval(cycleFn,cycleDur());
-document.getElementById('replay-btn').addEventListener('click',scramble);
-document.getElementById('cyc-sl').addEventListener('input',e=>{
- document.getElementById('cyc-v').textContent=e.target.value+'ms';
- // Apply live: swap the running interval for one at the new rate
- if(running&&cycleTimer){clearInterval(cycleTimer);cycleTimer=setInterval(cycleFn,+e.target.value);cycleCt.textContent=e.target.value+'ms';}
-});
-document.getElementById('settle-sl').addEventListener('input',e=>document.getElementById('settle-v').textContent=e.target.value+'ms');
-document.getElementById('settle-sl').addEventListener('change',scramble);
-loopTog.addEventListener('change',()=>{if(loopTog.checked&&!running)scramble();});
-document.getElementById('text-inp').addEventListener('keydown',e=>{if(e.key==='Enter')scramble()});
+ const totalTime=settleDur()*total+settleDur();
+ const thisTimer=cycleTimer;
+ later(()=>{if(cycleTimer===thisTimer){clearInterval(cycleTimer);cycleTimer=null;}},totalTime+cycleDur()*2);
+ }
+ function play(){
+ timers.forEach(clearTimeout);timers=[];
+ clearInterval(cycleTimer);cycleTimer=null;
+ cycle();
+ }
-scramble();
+ 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('charset-seg',d=>{charset=d.charset});
+ choices('delay-seg',d=>{settleMs=+d.ms});
+ choices('flicker-seg',d=>{cycleMs=+d.ms});
</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.html
index 6068f973..13be5b31 100644
--- a/index.html
+++ b/index.html
@@ -989,7 +989,7 @@ const CATS=[
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.'],
- ['scramble-text','Scramble / Glitch Text','Characters cycle randomly before locking left-to-right — decryption and sci-fi aesthetic.'],
+ ['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','Lines reveal via expanding clip-path mask — preserves kerning and typographic spacing exactly.'],
['marquee-ticker','Marquee / Ticker','Continuous horizontal scroll with seamless loop — duplicated content makes the reset invisible.'],