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: add 11 text-typography demos + READMEs; refresh home page to 72 animations
matind1fc7c0c81c4
diff --git a/animations/05-text-typography/README.md b/animations/05-text-typography/README.mdnew file mode 100644index 00000000..ae09e7b8--- /dev/null+++ b/animations/05-text-typography/README.md@@ -0,0 +1,33 @@+# 05 — Text & Typography++Animations specifically for type — where the letterforms themselves are the content and the motion serves the words.++## Animations++| Demo | Description |+|------|-------------|+| [Kinetic Typography](kinetic-typography/) | Phrases enter, transform, and exit in a choreographed timeline |+| [Typewriter Effect](typewriter-effect/) | Characters appear one at a time with a blinking cursor and natural timing variance |+| [Scramble / Glitch Text](scramble-text/) | Characters cycle randomly before locking left-to-right — decryption aesthetic |+| [Variable Font Morph](variable-font-morph/) | CSS font-variation-settings animates weight, slant, and casual axes |+| [Text Clip-Path Reveal](text-clip-path-reveal/) | Lines reveal via expanding clip-path — preserves kerning and typographic spacing |+| [Marquee / Ticker](marquee-ticker/) | Continuous horizontal scroll with seamless loop via duplicated content |+| [Text Morphing](text-morphing/) | One word transitions into another character by character |+| [Text Gradient Animation](text-gradient-animation/) | background-clip: text with animated background-position flows color through characters |+| [Outline to Fill](outline-to-fill/) | Hollow stroke letterforms fill with color via clip-path or opacity crossfade |+| [Enter/Exit Typography](enter-exit-typography/) | Three-act phrase lifecycle: enter → hold → exit, sequenced for storytelling |+| [Rotate Word Carousel](rotate-word-carousel/) | One keyword cycles through a list while the surrounding sentence stays static |++## Key principles++**Motion serves the words.** Every typographic animation should reinforce the meaning of the copy — a fragile word dissolves, a bold word snaps in, a soft word drifts. Generic transforms applied uniformly undermine the technique.++**Hold duration is critical.** The hold phase is where reading happens; enter and exit are punctuation. A 3-word phrase needs at least 600–800ms of hold. The most common mistake is making phrases too brief to read.++**Preserve typographic quality.** Clip-path reveals and whole-word techniques leave kerning and spacing untouched. Character-splitting (scramble, morph, stagger) can disrupt spacing — test at the intended font size.++**Reduced motion.** All demos show full text without motion when `prefers-reduced-motion: reduce` is set. Never hide or remove text as a reduced-motion fallback — only remove the animation.++## See also+- [02 — Entrance & Exit](../02-entrance-and-exit/) — element-level enter/exit including text-specific techniques like letter-by-letter stagger and word-by-word reveal+- [04 — Micro-Interactions](../04-micro-interactions/) — includes typewriter-adjacent patterns like the floating labeldiff --git a/animations/05-text-typography/enter-exit-typography/README.md b/animations/05-text-typography/enter-exit-typography/README.mdnew file mode 100644index 00000000..6cd7402b--- /dev/null+++ b/animations/05-text-typography/enter-exit-typography/README.md@@ -0,0 +1,72 @@+# Enter/Exit Typography++## What it is+Enter/exit typography treats each phrase as a three-act sequence: it enters the frame, holds long enough to be read, then exits to make way for the next. This is the full lifecycle of on-screen text in broadcast, presentation, and storytelling contexts. The key insight is that the exit is as important as the entry — the direction and character of each phrase's departure creates continuity with the next phrase's arrival.++## When to use it+- Sequential brand statements and manifesto sections+- Automated slideshow-style content that cycles without user interaction+- App onboarding flows that walk through a narrative step by step+- Ambient display screens and digital signage+- Hero sections with a rotating message queue++## How it works+Each phrase has a three-timer chain: enter animation fires, then after the enter duration a hold timer starts, then after the hold duration the exit animation fires, and finally after the exit duration `done()` is called to advance to the next phrase:++```js+function show(phrase, done) {+ el.textContent = phrase.text;+ el.classList.remove(...allClasses, 'hidden');+ el.classList.add(phrase.enter); // triggers CSS @keyframes++ setTimeout(() => { // after enter completes+ el.classList.remove(phrase.enter);+ el.classList.add(phrase.exit); // triggers exit @keyframes++ setTimeout(() => { // after exit completes+ el.classList.add('hidden');+ done(); // advance to next phrase+ }, EXIT_DURATION + 50);+ }, ENTER_DURATION + HOLD_DURATION);+}+```++Each enter/exit pair is a `@keyframes` rule:++```css+.enter-slide-right { animation: eSR 500ms ease-out forwards; }+.exit-slide-left { animation: xSL 400ms ease-in forwards; }++@keyframes eSR { from { opacity:0; transform:translateX(-50px) } to { opacity:1; transform:translateX(0) } }+@keyframes xSL { from { opacity:1; transform:translateX(0) } to { opacity:0; transform:translateX(60px) } }+```++The sequences loop by resetting `idx` to 0 after the last phrase:++```js+function cycle(idx = 0) {+ show(PHRASES[idx], () => {+ cycle((idx + 1) % PHRASES.length);+ });+}+```++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Enter duration | 500ms | Fast entry (300ms) = energetic; slow entry (800ms) = deliberate |+| Hold duration | 2000ms | Must exceed reading time: ~200ms per word minimum |+| Exit duration | 400ms | Usually shorter than enter — departure is punctuation, not the main event |+| Enter/exit pairing | Thematic | Matching directions (exit left → enter from left) implies continuation; mismatched implies contrast |++## Production notes+- **Hold duration is the most important parameter**: the animation is wasted if phrases don't have enough time to be read. A 5-word phrase needs at least 1000ms hold, preferably 1500–2000ms. Test by reading the phrase aloud at a comfortable pace — if you can't finish before the exit starts, extend the hold.+- **Directional continuity**: if a phrase exits upward, the next phrase entering from below creates a sense of being on the same vertical track. If a phrase exits left and the next enters from the right, it implies the user is moving "forward" through a sequence. These are conventions from film editing.+- **Auto-pause on tab blur**: use `document.addEventListener('visibilitychange', ...)` to pause the sequence when the tab loses focus. Phrases that advance while the user is away result in missed messages.+- **`prefers-reduced-motion`**: replace all motion with instant swaps — `display: none` → `display: block`. The text sequence still cycles, just without animation.+- **Framer Motion**: `<AnimatePresence>` handles enter/exit lifecycles for React components elegantly. Each phrase is conditionally rendered and gets `initial`, `animate`, and `exit` props.++## See also+- [Kinetic Typography](../kinetic-typography/) — the same pattern with per-phrase choreography choices driven by the copy's meaning+- [Rotate Word Carousel](../rotate-word-carousel/) — a single word within a static sentence cycling through a list+- [Text Morphing](../text-morphing/) — character-level transitions rather than full-phrase enter/exitdiff --git a/animations/05-text-typography/enter-exit-typography/index.html b/animations/05-text-typography/enter-exit-typography/index.htmlnew file mode 100644index 00000000..f47d1a56--- /dev/null+++ b/animations/05-text-typography/enter-exit-typography/index.html@@ -0,0 +1,182 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Enter/Exit Typography</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--enter-dur:500ms;--hold-dur:2000ms;--exit-dur:400ms;--enter-ease:ease-out;--exit-ease:ease-in}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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;overflow:hidden;position:relative}+ /* Phrase container */+ .phrase-el{+ position:absolute;inset:0;display:flex;align-items:center;justify-content:center;+ padding:32px;text-align:center;will-change:transform,opacity,filter;pointer-events:none+ }+ .phrase-text{font-family:Georgia,'Times New Roman',serif;font-size:clamp(28px,5vw,56px);line-height:1.2;color:#fff;font-style:italic}+ /* Enter states */+ .state-hidden{opacity:0}+ .enter-slide-up{animation:eSU var(--enter-dur) var(--enter-ease) forwards}+ .enter-slide-right{animation:eSR var(--enter-dur) var(--enter-ease) forwards}+ .enter-scale{animation:eSc var(--enter-dur) var(--enter-ease) forwards}+ .enter-blur{animation:eBl var(--enter-dur) var(--enter-ease) forwards}+ .enter-clip{animation:eCl var(--enter-dur) var(--enter-ease) forwards}+ @keyframes eSU{from{opacity:0;transform:translateY(40px)}to{opacity:1;transform:translateY(0)}}+ @keyframes eSR{from{opacity:0;transform:translateX(-50px)}to{opacity:1;transform:translateX(0)}}+ @keyframes eSc{from{opacity:0;transform:scale(.7)}to{opacity:1;transform:scale(1)}}+ @keyframes eBl{from{opacity:0;filter:blur(12px)}to{opacity:1;filter:blur(0)}}+ @keyframes eCl{from{opacity:1;clip-path:inset(0 100% 0 0)}to{opacity:1;clip-path:inset(0 0% 0 0)}}+ /* Exit states */+ .exit-slide-up{animation:xSU var(--exit-dur) var(--exit-ease) forwards}+ .exit-slide-left{animation:xSL var(--exit-dur) var(--exit-ease) forwards}+ .exit-scale{animation:xSc var(--exit-dur) var(--exit-ease) forwards}+ .exit-blur{animation:xBl var(--exit-dur) var(--exit-ease) forwards}+ .exit-clip{animation:xCl var(--exit-dur) var(--exit-ease) forwards}+ @keyframes xSU{from{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-50px)}}+ @keyframes xSL{from{opacity:1;transform:translateX(0)}to{opacity:0;transform:translateX(60px)}}+ @keyframes xSc{from{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.6)}}+ @keyframes xBl{from{opacity:1;filter:blur(0)}to{opacity:0;filter:blur(12px)}}+ @keyframes xCl{from{opacity:1;clip-path:inset(0 0% 0 0)}to{opacity:1;clip-path:inset(0 100% 0 0)}}+ /* Progress */+ .prog-dots{position:absolute;bottom:14px;left:50%;transform:translateX(-50%);display:flex;gap:6px}+ .prog-dot{width:6px;height:6px;border-radius:50%;background:var(--ui-border);transition:background .2s}+ .prog-dot.active{background:var(--ui-accent)}+ /* 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)}+ .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: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:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @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:480px}}+ @media(prefers-reduced-motion:reduce){.phrase-el{animation:none!important;opacity:1!important;transform:none!important;filter:none!important;clip-path:none!important}}+ </style>+</head>+<body>+<header>+ <h1>Enter/Exit Typography</h1>+ <p>Three-act phrase lifecycle: enter → hold → exit. Each phrase has its own choreography pair.</p>+</header>+<div class="layout">+ <div class="stage" id="stage">+ <div class="phrase-el state-hidden" id="phrase-el" aria-live="polite">+ <div class="phrase-text" id="phrase-text"></div>+ </div>+ <div class="prog-dots" id="prog-dots"></div>+ </div>+ <aside>+ <p class="note">Three acts per phrase: enter, hold, exit. The hold is where reading happens. Match exit direction to the next phrase's enter direction for visual continuity.</p>+ <div class="lbl">Enter Duration</div>+ <div class="sr"><input type="range" id="enter-sl" min="200" max="1000" value="500" step="50"><span class="sv" id="enter-v">500ms</span></div>+ <div class="lbl">Hold Duration</div>+ <div class="sr"><input type="range" id="hold-sl" min="500" max="4000" value="2000" step="100"><span class="sv" id="hold-v">2.0s</span></div>+ <div class="lbl">Exit Duration</div>+ <div class="sr"><input type="range" id="exit-sl" min="200" max="800" value="400" step="50"><span class="sv" id="exit-v">400ms</span></div>+ <div class="div"></div>+ <div class="kv"><span>Phrase</span><span class="v" id="phrase-kv">1 / 5</span></div>+ <div class="kv"><span>Phase</span><span class="v" id="phase-kv">—</span></div>+ <div class="div"></div>+ <button class="rst" id="replay-btn">↺ Replay</button>+ <label class="tog"><input type="checkbox" id="loop-tog" checked><span>Loop</span></label>+ </aside>+</div>+<script>+const PHRASES=[+ {text:'Everything starts',enter:'enter-slide-right',exit:'exit-slide-up'},+ {text:'with a blank page.',enter:'enter-slide-up',exit:'exit-blur'},+ {text:'Then words arrive.',enter:'enter-blur',exit:'exit-slide-left'},+ {text:'Then motion.',enter:'enter-scale',exit:'exit-scale'},+ {text:'Then meaning.',enter:'enter-clip',exit:'exit-clip'},+];+let idx=0,timer=null;+const phraseEl=document.getElementById('phrase-el');+const phraseText=document.getElementById('phrase-text');+const dotsEl=document.getElementById('prog-dots');+const phraseKv=document.getElementById('phrase-kv');+const phaseKv=document.getElementById('phase-kv');++function buildDots(){+ dotsEl.innerHTML='';+ PHRASES.forEach((_,i)=>{const d=document.createElement('div');d.className='cycle-dot prog-dot';dotsEl.appendChild(d);});+}+function activeDot(i){dotsEl.querySelectorAll('.prog-dot').forEach((d,j)=>d.classList.toggle('active',j===i));}++function getEnterDur(){return+document.getElementById('enter-sl').value}+function getHoldDur(){return+document.getElementById('hold-sl').value}+function getExitDur(){return+document.getElementById('exit-sl').value}++const enterClasses=['enter-slide-up','enter-slide-right','enter-scale','enter-blur','enter-clip'];+const exitClasses=['exit-slide-up','exit-slide-left','exit-scale','exit-blur','exit-clip'];+const allPhaseClasses=[...enterClasses,...exitClasses,'state-hidden'];++function show(i,done){+ const p=PHRASES[i];+ phraseText.textContent=p.text;+ phraseEl.classList.remove(...allPhaseClasses);+ phraseEl.classList.add('state-hidden');+ phraseKv.textContent=(i+1)+' / '+PHRASES.length;+ activeDot(i);+ requestAnimationFrame(()=>requestAnimationFrame(()=>{+ phaseKv.textContent='Enter';+ phraseEl.classList.remove('state-hidden');+ phraseEl.classList.add(p.enter);+ const enterDur=getEnterDur();+ timer=setTimeout(()=>{+ phaseKv.textContent='Hold';+ timer=setTimeout(()=>{+ phaseKv.textContent='Exit';+ phraseEl.classList.remove(p.enter);+ phraseEl.classList.add(p.exit);+ timer=setTimeout(()=>{phraseEl.classList.add('state-hidden');done();},getExitDur()+50);+ },getHoldDur());+ },enterDur+50);+ }));+}++function cycle(){+ show(idx,()=>{+ idx=(idx+1)%PHRASES.length;+ if(idx>0||document.getElementById('loop-tog').checked){+ timer=setTimeout(cycle,120);+ }else{phaseKv.textContent='Done';}+ });+}++function start(){+ if(timer)clearTimeout(timer);+ idx=0;buildDots();+ phraseEl.classList.add('state-hidden');+ setTimeout(cycle,200);+}++document.getElementById('replay-btn').addEventListener('click',start);+document.getElementById('enter-sl').addEventListener('input',e=>{+ document.getElementById('enter-v').textContent=e.target.value+'ms';+ document.documentElement.style.setProperty('--enter-dur',e.target.value+'ms');+});+document.getElementById('hold-sl').addEventListener('input',e=>{+ document.getElementById('hold-v').textContent=(e.target.value/1000).toFixed(1)+'s';+ document.documentElement.style.setProperty('--hold-dur',e.target.value+'ms');+});+document.getElementById('exit-sl').addEventListener('input',e=>{+ document.getElementById('exit-v').textContent=e.target.value+'ms';+ document.documentElement.style.setProperty('--exit-dur',e.target.value+'ms');+});++start();+</script>+</body>+</html>diff --git a/animations/05-text-typography/kinetic-typography/README.md b/animations/05-text-typography/kinetic-typography/README.mdnew file mode 100644index 00000000..ba352001--- /dev/null+++ b/animations/05-text-typography/kinetic-typography/README.md@@ -0,0 +1,72 @@+# Kinetic Typography++## What it is+Kinetic typography is the practice of animating text so that its motion reinforces its meaning. Rather than animating text as a generic UI element, each word or phrase is choreographed — scale, trajectory, timing, and rhythm are all chosen to serve the specific copy. It originates from motion graphics and broadcast design but has migrated to web via CSS animations and canvas-based tools.++## When to use it+- Opening sequences and splash screens where brand personality is established+- Video-style storytelling sections on marketing sites+- Presentation slides that need to feel like motion graphics+- App onboarding flows where each step has a narrative beat+- Anywhere the text itself is the content, not a label for something else++## How it works+Each phrase is a CSS element with an entry animation, a hold period, and an exit animation. A JavaScript timeline chains them with `setTimeout`:++```js+const PHRASES = [+ { text: 'EVERY', enter: 'enter-scale', exit: 'exit-up', hold: 1400 },+ { text: 'MOMENT', enter: 'enter-big', exit: 'exit-shrink', hold: 1800 },+];++function showPhrase(i) {+ const p = PHRASES[i];+ el.textContent = p.text;+ el.className = p.enter; // triggers @keyframes+}++function run(idx = 0) {+ showPhrase(idx);+ setTimeout(() => {+ exitPhrase(idx, () => {+ if (idx + 1 < PHRASES.length) run(idx + 1);+ });+ }, ENTER_DUR + PHRASES[idx].hold);+}+```++Each enter and exit is a standalone `@keyframes` rule:++```css+.enter-scale { animation: kEnterScale 600ms ease-out forwards; }+.exit-up { animation: kExitUp 400ms ease-in forwards; }++@keyframes kEnterScale { from { opacity:0; transform:scale(.5) } to { opacity:1; transform:scale(1) } }+@keyframes kExitUp { from { opacity:1; transform:translateY(0) } to { opacity:0; transform:translateY(-50px) } }+```++Playback speed is controlled via a CSS custom property used in every `calc()`:++```css+.enter-scale { animation-duration: calc(600ms / var(--spd)); }+```++## Key parameters+| Parameter | Typical range | Effect |+|-----------|--------------|--------|+| Enter duration | 400–800ms | Fast entries feel punchy; slow entries feel deliberate |+| Hold duration | 1000–2500ms | Must be long enough to read the phrase; subtitle reading speed is ~200ms/word |+| Exit duration | 300–500ms | Exits are usually shorter than entries — departure is less important than arrival |+| Playback speed | 0.5×–2× | Multiply all durations by inverse of speed factor |++## Production notes+- **Copy-first choreography**: the motion should be chosen for the words, not the other way around. Soft/gentle words dissolve; heavy words slam in; fragile words flutter. Generic enters and exits applied uniformly undermine the whole technique.+- **Hold duration is critical**: reading speed for subtitles is roughly 200ms per word minimum. A 3-word phrase needs at least 600ms of hold, ideally 1000ms+. The most common mistake is holding too briefly.+- **Audio sync**: kinetic typography originated in sound-synced broadcast. Even on web (without audio), timing phrases to a mental beat makes sequences feel more intentional. Think in measures, not just milliseconds.+- **CSS vs canvas**: CSS `@keyframes` is sufficient for most web uses. For audio-synced or highly complex sequences, GSAP's timeline API (`gsap.timeline()`) is the production-grade choice. Lottie (JSON-based After Effects export) handles pre-rendered kinetic sequences that are too complex for CSS.+- **`prefers-reduced-motion`**: show all phrases simultaneously or show only the final phrase — don't suppress the text itself.++## See also+- [Enter/Exit Typography](../enter-exit-typography/) — the same enter→hold→exit pattern focused on prose storytelling+- [Rotate Word Carousel](../rotate-word-carousel/) — a single cycling word rather than full phrase sequences+- [Text Clip-Path Reveal](../text-clip-path-reveal/) — one of the enter techniques used here as a standalone patterndiff --git a/animations/05-text-typography/kinetic-typography/index.html b/animations/05-text-typography/kinetic-typography/index.htmlnew file mode 100644index 00000000..c93ca477--- /dev/null+++ b/animations/05-text-typography/kinetic-typography/index.html@@ -0,0 +1,179 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Kinetic Typography</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--spd:1}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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;overflow:hidden;position:relative;display:flex;align-items:center;justify-content:center}+ /* Phrase display */+ #phrase{position:absolute;display:flex;flex-direction:column;align-items:center;justify-content:center;width:100%;padding:32px;text-align:center}+ .kw{font-family:Georgia,'Times New Roman',serif;font-size:clamp(40px,8vw,90px);line-height:1;letter-spacing:-0.02em;color:#fff;will-change:transform,opacity;display:block}+ .kw.sub{font-family:monospace;font-size:clamp(11px,1.5vw,14px);letter-spacing:4px;text-transform:uppercase;color:var(--ui-muted);margin-top:12px}+ /* Enter/exit animations */+ .kw{opacity:0;transform:translateY(0) scale(1)}+ .enter-scale{animation:kEnterScale calc(600ms / var(--spd)) ease-out forwards}+ .enter-slide{animation:kEnterSlide calc(500ms / var(--spd)) ease-out forwards}+ .enter-fade{animation:kEnterFade calc(400ms / var(--spd)) ease-out forwards}+ .enter-big{animation:kEnterBig calc(700ms / var(--spd)) cubic-bezier(.2,1.1,.4,1) forwards}+ .enter-clip{animation:kEnterClip calc(600ms / var(--spd)) ease-out forwards}+ .exit-up{animation:kExitUp calc(400ms / var(--spd)) ease-in forwards}+ .exit-fade{animation:kExitFade calc(300ms / var(--spd)) ease-in forwards}+ .exit-shrink{animation:kExitShrink calc(500ms / var(--spd)) ease-in forwards}+ .exit-right{animation:kExitRight calc(400ms / var(--spd)) ease-in forwards}+ @keyframes kEnterScale{from{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}+ @keyframes kEnterSlide{from{opacity:0;transform:translateX(-60px)}to{opacity:1;transform:translateX(0)}}+ @keyframes kEnterFade{from{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}+ @keyframes kEnterBig{from{opacity:0;transform:scale(2.5)}to{opacity:1;transform:scale(1)}}+ @keyframes kEnterClip{from{opacity:0;clip-path:inset(0 100% 0 0)}to{opacity:1;clip-path:inset(0 0% 0 0)}}+ @keyframes kExitUp{from{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-50px)}}+ @keyframes kExitFade{from{opacity:1}to{opacity:0}}+ @keyframes kExitShrink{from{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.3)}}+ @keyframes kExitRight{from{opacity:1;transform:translateX(0)}to{opacity:0;transform:translateX(80px)}}+ /* Beat markers */+ .beat-bar{position:absolute;bottom:0;left:0;right:0;height:3px;background:var(--ui-border)}+ .beat-fill{height:100%;background:var(--ui-accent);width:0%;transition:width 100ms linear}+ /* Phrase counter */+ .phrase-counter{position:absolute;top:14px;right:14px;font-size:10px;color:var(--ui-muted);letter-spacing:1px}+ /* 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)}+ .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:36px;text-align:right;color:var(--ui-text)}+ .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:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:420px}}+ @media(prefers-reduced-motion:reduce){.kw{animation:none!important;opacity:1!important;transform:none!important}}+ </style>+</head>+<body>+<header>+ <h1>Kinetic Typography</h1>+ <p>Text in motion — phrases enter, transform, and exit in a coordinated timeline.</p>+</header>+<div class="layout">+ <div class="stage">+ <div id="phrase" aria-live="polite"></div>+ <div class="phrase-counter" id="counter">1 / 6</div>+ <div class="beat-bar"><div class="beat-fill" id="beat-fill"></div></div>+ </div>+ <aside>+ <p class="note">Kinetic typography is choreography for words. Each transform should reinforce the meaning — a soft word dissolves; a hard word snaps in.</p>+ <div class="lbl">Playback Speed</div>+ <div class="sr"><input type="range" id="spd-sl" min="5" max="20" value="10" step="1"><span class="sv" id="spd-v">1×</span></div>+ <div class="div"></div>+ <div class="kv"><span>Phrase</span><span class="v" id="phrase-kv">1 / 6</span></div>+ <div class="kv"><span>State</span><span class="v" id="state-kv">Playing</span></div>+ <div class="div"></div>+ <button class="rst" id="play-btn">▶ Play / Restart</button>+ <label class="tog"><input type="checkbox" id="loop-tog"><span>Loop sequence</span></label>+ <label class="tog"><input type="checkbox" id="beat-tog" checked><span>Show progress bar</span></label>+ </aside>+</div>+<script>+const PHRASES=[+ {text:'EVERY',sub:'word has',enter:'enter-scale',exit:'exit-up',hold:1400,color:'#c9d1d9'},+ {text:'A WEIGHT',sub:null,enter:'enter-slide',exit:'exit-right',hold:1600,color:'#58a6ff'},+ {text:'AND',sub:null,enter:'enter-fade',exit:'exit-fade',hold:900,color:'#8b949e'},+ {text:'A MOMENT',sub:null,enter:'enter-big',exit:'exit-shrink',hold:1800,color:'#d2a8ff'},+ {text:'IN MOTION',sub:'it becomes',enter:'enter-clip',exit:'exit-up',hold:1600,color:'#56d364'},+ {text:'MEANING.',sub:null,enter:'enter-scale',exit:'exit-fade',hold:2200,color:'#ffa657'},+];+let idx=0,timer=null,running=false,speed=1;+const phraseEl=document.getElementById('phrase');+const counterEl=document.getElementById('counter');+const phraseKv=document.getElementById('phrase-kv');+const stateKv=document.getElementById('state-kv');+const beatFill=document.getElementById('beat-fill');++function ms(n){return Math.round(n/speed)}++function showPhrase(i){+ const p=PHRASES[i];+ phraseEl.innerHTML='';+ const w=document.createElement('span');w.className='kw';+ w.style.color=p.color;w.textContent=p.text;phraseEl.appendChild(w);+ if(p.sub){const s=document.createElement('span');s.className='kw sub';s.textContent=p.sub;phraseEl.appendChild(s);}+ counterEl.textContent=(i+1)+' / '+PHRASES.length;+ phraseKv.textContent=(i+1)+' / '+PHRASES.length;+ const pct=((i+1)/PHRASES.length*100).toFixed(0)+'%';+ if(document.getElementById('beat-tog').checked)beatFill.style.width=pct;+ requestAnimationFrame(()=>{+ w.classList.add(p.enter);+ if(p.sub)phraseEl.querySelectorAll('.sub').forEach(s=>{s.style.animationDelay='200ms';s.classList.add(p.enter);});+ });+}++function exitPhrase(i,done){+ const p=PHRASES[i];+ phraseEl.querySelectorAll('.kw').forEach(w=>{+ w.classList.remove(p.enter);w.classList.add(p.exit);+ });+ setTimeout(done,ms(450));+}++function run(){+ if(running)return;running=true;stateKv.textContent='Playing';+ idx=0;+ function step(){+ showPhrase(idx);+ timer=setTimeout(()=>{+ exitPhrase(idx,()=>{+ idx++;+ if(idx<PHRASES.length){setTimeout(step,ms(120));}+ else{+ running=false;stateKv.textContent='Done';+ if(document.getElementById('loop-tog').checked){beatFill.style.width='0%';setTimeout(run,ms(800));}+ }+ });+ },ms(500)+ms(p.hold));+ }+ function p_hold(){return PHRASES[idx];}+ function step2(){+ showPhrase(idx);+ const hold=PHRASES[idx].hold;+ timer=setTimeout(()=>{+ exitPhrase(idx,()=>{+ idx++;+ if(idx<PHRASES.length){setTimeout(step2,ms(120));}+ else{+ running=false;stateKv.textContent='Done';+ if(document.getElementById('loop-tog').checked){beatFill.style.width='0%';setTimeout(run,ms(800));}+ }+ });+ },ms(500+hold));+ }+ step2();+}++document.getElementById('play-btn').addEventListener('click',()=>{+ if(timer)clearTimeout(timer);running=false;beatFill.style.width='0%';+ setTimeout(run,50);+});+document.getElementById('spd-sl').addEventListener('input',e=>{+ speed=e.target.value/10;+ document.getElementById('spd-v').textContent=speed.toFixed(1)+'×';+ document.documentElement.style.setProperty('--spd',speed);+});+document.getElementById('beat-tog').addEventListener('change',e=>{+ beatFill.parentElement.style.display=e.target.checked?'block':'none';+});++run();+</script>+</body>+</html>diff --git a/animations/05-text-typography/marquee-ticker/README.md b/animations/05-text-typography/marquee-ticker/README.mdnew file mode 100644index 00000000..def5965d--- /dev/null+++ b/animations/05-text-typography/marquee-ticker/README.md@@ -0,0 +1,86 @@+# Marquee / Ticker++## What it is+A marquee is text (or any content) that scrolls continuously in one direction without pausing. The seamless loop is achieved by duplicating the content so that when the first copy exits, the second copy has arrived at exactly the same position — making the reset invisible. Marquees are used for news tickers, brand statements, infinite scroll walls, and ambient content that doesn't demand focus.++## When to use it+- Scrolling news tickers and sports scores+- Branded content rails on agency/portfolio sites ("CLIENT LIST · WORK · PROCESS ·")+- Infinite logo strips (scrolling client logos)+- Ambient background text in hero sections+- Two-row opposite-direction marquees as a decorative pattern++## How it works+The track contains the content duplicated exactly twice. The CSS animation translates the track by `-50%` of its total width — which equals the width of one copy. At the loop point, the second copy is at the position the first copy started, making the transition invisible:++```html+<div class="overflow-container">+ <div class="track">+ <span>Content · Content · Content ·</span>+ <span>Content · Content · Content ·</span> <!-- duplicate -->+ </div>+</div>+```++```css+.overflow-container { overflow: hidden; }++.track {+ display: flex;+ width: max-content;+ white-space: nowrap;+ animation: marquee 10s linear infinite;+}++@keyframes marquee {+ from { transform: translateX(0); }+ to { transform: translateX(-50%); }+}+```++To calculate the correct duration for a target pixel-per-second speed:++```js+// The animation travels exactly one copy's width (50% of the full track)+const oneCopyWidth = trackEl.scrollWidth / 2;+const durationSeconds = oneCopyWidth / pixelsPerSecond;+trackEl.style.animationDuration = durationSeconds + 's';+```++Pause on hover:++```css+.overflow-container:hover .track {+ animation-play-state: paused;+}+```++Reverse direction by animating from `-50%` to `0`:++```css+@keyframes marquee-reverse {+ from { transform: translateX(-50%); }+ to { transform: translateX(0); }+}+```++## Key parameters+| Parameter | Typical range | Effect |+|-----------|--------------|--------|+| Speed | 40–150px/sec | News tickers: 40–60; branded rails: 80–120; dramatic: 150+ |+| Font size | 24–96px | Large type (60–96px) is the dominant agency pattern; smaller for news tickers |+| Gap between items | 32–80px | Breathing room between repetitions — use a separator character (· ★ —) |+| Direction | LTR or RTL | Convention: left-to-right for Western text; RTL for Arabic/Hebrew |++## Production notes+- **Duplicate once, not more**: duplicating twice is enough for any viewport width as long as one copy is wider than the viewport. More duplicates waste DOM. If your text is very short, add more repetitions within each copy rather than more copies.+- **`width: max-content`** on the track prevents line wrapping. Without it, text wraps at the container width, breaking the layout.+- **`will-change: transform`** on the track element promotes it to a GPU compositing layer. Measure performance before adding — it reserves GPU memory and can cause issues on low-end mobile.+- **Pause on hover is UX-critical**: users who want to read specific content need to be able to pause. The `:hover` CSS approach is zero JavaScript.+- **Accessibility**: add `aria-live="off"` to the marquee container — screen readers should not continuously announce scrolling content. If the content contains links, ensure they are reachable by keyboard (focus state visible, tabIndex correct).+- **Reduced motion**: `@media (prefers-reduced-motion: reduce)` → `animation-play-state: paused`. The content is still visible, just static.+- **Swiper.js** has an `autoplay` + `loop` mode that handles marquee behavior with touch support and accessibility built in.++## See also+- [Rotate Word Carousel](../rotate-word-carousel/) — single cycling word rather than continuous horizontal scroll+- [Kinetic Typography](../kinetic-typography/) — text that moves with narrative intent rather than ambient loopingdiff --git a/animations/05-text-typography/marquee-ticker/index.html b/animations/05-text-typography/marquee-ticker/index.htmlnew file mode 100644index 00000000..540da249--- /dev/null+++ b/animations/05-text-typography/marquee-ticker/index.html@@ -0,0 +1,140 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Marquee / Ticker</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--marq-spd:80px;--marq-size:48px;--marq-gap:48px}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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;overflow:hidden;display:flex;flex-direction:column;justify-content:center;gap:0}+ /* Marquee row */+ .marq-row{overflow:hidden;padding:16px 0;border-bottom:1px solid var(--ui-border);position:relative}+ .marq-row:last-child{border-bottom:none}+ .marq-row.accent{background:rgba(88,166,255,.05)}+ .marq-track{display:flex;width:max-content;white-space:nowrap;animation:marqL linear infinite}+ .marq-track.rev{animation-name:marqR}+ .marq-row:hover .marq-track{animation-play-state:paused}+ @keyframes marqL{from{transform:translateX(0)}to{transform:translateX(-50%)}}+ @keyframes marqR{from{transform:translateX(-50%)}to{transform:translateX(0)}}+ .marq-item{font-family:Georgia,'Times New Roman',serif;font-size:var(--marq-size);font-style:italic;line-height:1;color:#fff;padding:0 var(--marq-gap);display:flex;align-items:center;gap:var(--marq-gap)}+ .marq-item.rev-row{color:rgba(255,255,255,.6)}+ .sep{color:var(--ui-accent);font-style:normal;font-size:.6em;opacity:.7}+ /* Pause indicator */+ .pause-hint{position:absolute;right:12px;top:50%;transform:translateY(-50%);font-size:9px;letter-spacing:1px;color:var(--ui-muted);opacity:0;transition:opacity .2s;pointer-events:none;background:var(--ui-bg);padding:3px 8px;border-radius:3px}+ .marq-row:hover .pause-hint{opacity:1}+ /* 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:monospace;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:monospace;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:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:380px}}+ @media(prefers-reduced-motion:reduce){.marq-track{animation-play-state:paused!important}}+ </style>+</head>+<body>+<header>+ <h1>Marquee / Ticker</h1>+ <p>Continuous horizontal scroll with duplicated content — the seam is invisible at the loop point.</p>+</header>+<div class="layout">+ <div class="stage" id="stage">+ <!-- built by JS -->+ </div>+ <aside>+ <p class="note">Animate exactly the width of ONE copy. At -50% translateX, the second copy is in the first's original position — the reset is invisible. Hover pauses.</p>+ <div class="lbl">Speed (px/sec)</div>+ <div class="sr"><input type="range" id="spd-sl" min="20" max="200" value="80" step="10"><span class="sv" id="spd-v">80</span></div>+ <div class="lbl">Font Size</div>+ <div class="sr"><input type="range" id="size-sl" min="24" max="96" value="48" step="4"><span class="sv" id="size-v">48px</span></div>+ <div class="lbl">Gap Between Items</div>+ <div class="sr"><input type="range" id="gap-sl" min="16" max="96" value="48" step="4"><span class="sv" id="gap-v">48px</span></div>+ <div class="lbl">Separator</div>+ <select id="sep-sel">+ <option value="·">Bullet ·</option>+ <option value="★">Star ★</option>+ <option value="—">Dash —</option>+ <option value="✦" selected>Asterisk ✦</option>+ </select>+ <div class="div"></div>+ <div class="lbl">Marquee Text</div>+ <input type="text" id="text-inp" value="Animation Atlas">+ <button class="rst" id="apply-btn">↺ Apply</button>+ </aside>+</div>+<script>+ const stage=document.getElementById('stage');++ function buildRow(text,sep,reverse,className){+ const row=document.createElement('div');row.className='marq-row'+(className?' '+className:'');+ const hint=document.createElement('div');hint.className='pause-hint';hint.textContent='PAUSED';row.appendChild(hint);+ const track=document.createElement('div');track.className='marq-track'+(reverse?' rev':'');+ // Duplicate 4× for seamless loop+ for(let i=0;i<4;i++){+ const item=document.createElement('div');item.className='marq-item'+(reverse?' rev-row':'');+ item.innerHTML=text+'<span class="sep" aria-hidden="true">'+sep+'</span>';+ track.appendChild(item);+ }+ row.appendChild(track);+ updateSpeed(track);+ return row;+ }++ function getContent(){+ return document.getElementById('text-inp').value||'Animation Atlas';+ }+ function getSep(){return document.getElementById('sep-sel').value}++ function updateSpeed(track){+ const spd=+document.getElementById('spd-sl').value;+ // Estimate total track width: approximate by counting chars+ const text=getContent();+ const approxW=(text.length*40+100)*2; // 2 copies = -50% travel distance+ const dur=Math.max(approxW/spd,2);+ track.style.animationDuration=dur.toFixed(1)+'s';+ }++ function rebuild(){+ const text=getContent();const sep=getSep();+ stage.innerHTML='';+ stage.appendChild(buildRow(text,sep,false,''));+ stage.appendChild(buildRow(text,sep,true,'accent'));+ stage.appendChild(buildRow(text+' · '+text,sep,false,''));+ }++ function refreshSpeeds(){+ document.querySelectorAll('.marq-track').forEach(t=>updateSpeed(t));+ document.documentElement.style.setProperty('--marq-spd',document.getElementById('spd-sl').value+'px');+ }++ document.getElementById('spd-sl').addEventListener('input',e=>{+ document.getElementById('spd-v').textContent=e.target.value;refreshSpeeds();+ });+ document.getElementById('size-sl').addEventListener('input',e=>{+ document.getElementById('size-v').textContent=e.target.value+'px';+ document.documentElement.style.setProperty('--marq-size',e.target.value+'px');+ });+ document.getElementById('gap-sl').addEventListener('input',e=>{+ document.getElementById('gap-v').textContent=e.target.value+'px';+ document.documentElement.style.setProperty('--marq-gap',e.target.value+'px');+ });+ document.getElementById('apply-btn').addEventListener('click',rebuild);+ document.getElementById('sep-sel').addEventListener('change',rebuild);++ rebuild();+</script>+</body>+</html>diff --git a/animations/05-text-typography/outline-to-fill/README.md b/animations/05-text-typography/outline-to-fill/README.mdnew file mode 100644index 00000000..7695fd8d--- /dev/null+++ b/animations/05-text-typography/outline-to-fill/README.md@@ -0,0 +1,93 @@+# Outline to Fill++## What it is+Outline-to-fill starts text as hollow letterforms — a visible stroke with a transparent interior — then fills the characters with color. The transition reads as text being "inked in," giving it a sculptural, hand-crafted quality. Two implementation approaches exist: a clip-path reveal (directional, like paint being applied from one side) and an opacity crossfade (simultaneous, like ink bleeding in uniformly).++## When to use it+- Hero words on posters and editorial-style sites where the letterforms themselves are the visual+- Logo reveals and wordmark animations+- Section headings that activate on scroll entry+- Any headline where a simple fade-in would be too plain but full kinetic typography is too complex++## How it works+`-webkit-text-stroke` creates the hollow outline; a `color: transparent` makes the fill invisible. Two identical text elements are layered — the outline layer always visible, the fill layer revealed by a clip-path animation:++```html+<div class="text-wrap">+ <div class="outline-layer">OUTLINE</div> <!-- always visible: stroke, no fill -->+ <div class="fill-layer">OUTLINE</div> <!-- revealed: stroke + fill -->+</div>+```++```css+.text-wrap { position: relative; display: inline-block; }++.outline-layer {+ -webkit-text-stroke: 2px #58a6ff;+ color: transparent;+ position: relative;+ z-index: 2;+}++.fill-layer {+ position: absolute;+ inset: 0;+ -webkit-text-stroke: 2px #58a6ff;+ color: #58a6ff;+ clip-path: inset(100% 0 0 0); /* fully hidden initially (bottom-up) */+ transition: clip-path 900ms ease-in-out;+ z-index: 1;+}++.fill-layer.filled {+ clip-path: inset(0%); /* fully revealed */+}+```++Trigger the fill in JavaScript:+```js+document.querySelector('.fill-layer').classList.add('filled');+```++Direction variants change the starting `clip-path`:+```css+/* Bottom to top (default) */+clip-path: inset(100% 0 0 0);++/* Top to bottom */+clip-path: inset(0 0 100% 0);++/* Left to right */+clip-path: inset(0 100% 0 0);++/* Center outward */+clip-path: inset(50% 0); /* top+bottom each at 50% = nothing visible */+```++For the opacity crossfade variant (no clip-path):+```css+.stroke-only { opacity: 1; transition: opacity 900ms ease; }+.fill-only { opacity: 0; transition: opacity 900ms ease; }++.filled .stroke-only { opacity: 0; }+.filled .fill-only { opacity: 1; }+```++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Fill duration | 900ms | 400ms = snappy; 1500ms = slow and dramatic |+| Stroke width | 2px | Thinner reads as precise/elegant; thicker reads as bold/graphic |+| Direction | Bottom-up | Bottom-up reads as being filled like a container; left-right reads like writing |+| Easing | ease-in-out | Symmetrical ease gives a smooth start and end |++## Production notes+- **`-webkit-text-stroke` is non-standard**: it is supported in all modern browsers (Chrome, Firefox, Safari, Edge) but is not in the CSS specification. The standard alternative is `text-shadow` with a spread — less crisp but more compatible. For production, test the stroke rendering in your target browsers and font size.+- **Stroke applies outside the fill**: `-webkit-text-stroke` distributes the stroke both inside and outside the character path. At thick values, it can eat into the letterform's counter (interior space). Use thin strokes (1–3px) for body sizes; thicker only for very large display type.+- **Two-element overhead**: the technique requires two DOM elements per animated word. For many words or dynamic content, consider generating these programmatically or using a single-element approach (CSS mask with SVG text, or Canvas).+- **GSAP**: animate `clipPath` on the fill layer element directly. `gsap.to(fillLayer, { clipPath: 'inset(0%)', duration: 0.9, ease: 'power2.inOut' })`.++## See also+- [Text Gradient Animation](../text-gradient-animation/) — fills text with a moving gradient instead of a solid color+- [Text Clip-Path Reveal](../text-clip-path-reveal/) — the same clip-path reveal technique applied to full lines of text+- [Clip-Path Reveal](../../02-entrance-and-exit/clip-path-reveal/) — the general-purpose element clip-path revealdiff --git a/animations/05-text-typography/outline-to-fill/index.html b/animations/05-text-typography/outline-to-fill/index.htmlnew file mode 100644index 00000000..931d802b--- /dev/null+++ b/animations/05-text-typography/outline-to-fill/index.html@@ -0,0 +1,201 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Outline to Fill</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--fill-dur:900ms;--fill-ease:ease-in-out;--stroke-color:#58a6ff;--fill-color:#58a6ff;--stroke-w:2;--fill-dir:up}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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:40px;padding:32px}+ /* Shared text style */+ .otf-text{+ font-family:Georgia,'Times New Roman',serif;+ font-size:clamp(52px,9vw,100px);+ line-height:1;+ letter-spacing:0.06em;+ font-style:italic;+ -webkit-user-select:none;user-select:none+ }+ /* Variant A: bottom-up fill via stacked layers */+ .otf-wrap{position:relative;display:inline-block}+ .outline-layer{+ -webkit-text-stroke:var(--stroke-w)px var(--stroke-color);+ color:transparent;+ position:relative;z-index:2+ }+ .fill-layer{+ position:absolute;inset:0;+ -webkit-text-stroke:var(--stroke-w)px var(--stroke-color);+ color:var(--fill-color);+ clip-path:inset(100% 0 0 0);+ transition:clip-path var(--fill-dur) var(--fill-ease);+ z-index:1+ }+ .fill-layer.dir-down{clip-path:inset(0 0 100% 0)}+ .fill-layer.dir-left{clip-path:inset(0 0 0 100%)}+ .fill-layer.dir-right{clip-path:inset(0 100% 0 0)}+ .fill-layer.dir-center{clip-path:inset(50% 0)}+ .fill-layer.filled{clip-path:inset(0%)!important}+ /* Variant B: stroke fade, fill fade */+ .stroke-fade-wrap{position:relative;display:inline-block}+ .stroke-only{+ -webkit-text-stroke:var(--stroke-w)px var(--stroke-color);+ color:transparent;+ transition:opacity var(--fill-dur) var(--fill-ease)+ }+ .fill-only{+ position:absolute;inset:0;+ color:var(--fill-color);+ opacity:0;+ transition:opacity var(--fill-dur) var(--fill-ease)+ }+ .stroke-fade-wrap.filled .stroke-only{opacity:0}+ .stroke-fade-wrap.filled .fill-only{opacity:1}+ /* Label */+ .var-label{font-size:10px;letter-spacing:2px;text-transform:uppercase;color:var(--ui-muted)}+ /* 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:monospace;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:monospace;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)}+ .color-row{display:flex;gap:8px;align-items:center;font-size:10px;color:var(--ui-muted);flex-wrap:wrap}+ input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @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{height:auto;min-height:440px}}+ @media(prefers-reduced-motion:reduce){.fill-layer,.stroke-only,.fill-only{transition:none!important}.fill-layer{clip-path:inset(0%)!important}.stroke-fade-wrap.filled .fill-only{opacity:1!important}.stroke-fade-wrap.filled .stroke-only{opacity:0!important}}+ </style>+</head>+<body>+<header>+ <h1>Outline to Fill</h1>+ <p>Text starts as a hollow stroke then fills with color — two techniques: clip-path reveal and opacity crossfade.</p>+</header>+<div class="layout">+ <div class="stage">+ <div>+ <div class="var-label" style="text-align:center;margin-bottom:12px">Clip-path Fill</div>+ <div class="otf-wrap" id="otf-wrap">+ <div class="otf-text outline-layer" id="outline-layer">OUTLINE</div>+ <div class="otf-text fill-layer" id="fill-layer">OUTLINE</div>+ </div>+ </div>+ <div>+ <div class="var-label" style="text-align:center;margin-bottom:12px">Stroke → Fill Fade</div>+ <div class="stroke-fade-wrap" id="stroke-wrap">+ <div class="otf-text stroke-only" id="stroke-only">OUTLINE</div>+ <div class="otf-text fill-only" id="fill-only">OUTLINE</div>+ </div>+ </div>+ </div>+ <aside>+ <p class="note">Two stacked text elements: the outline layer always visible, the filled layer revealed by clip-path from the chosen direction. -webkit-text-stroke is non-standard but universally supported.</p>+ <div class="lbl">Direction</div>+ <select id="dir-sel">+ <option value="up" selected>Up (bottom to top)</option>+ <option value="down">Down (top to bottom)</option>+ <option value="left">Left (right to left)</option>+ <option value="right">Right (left to right)</option>+ <option value="center">Center outward</option>+ </select>+ <div class="lbl">Fill Duration</div>+ <div class="sr"><input type="range" id="dur-sl" min="300" max="2000" value="900" step="50"><span class="sv" id="dur-v">900ms</span></div>+ <div class="lbl">Stroke Width</div>+ <div class="sr"><input type="range" id="sw-sl" min="1" max="6" value="2" step="1"><span class="sv" id="sw-v">2px</span></div>+ <div class="lbl">Colors</div>+ <div class="color-row">+ <span>Stroke</span><input type="color" id="stroke-pick" value="#58a6ff" aria-label="Stroke color">+ <span>Fill</span><input type="color" id="fill-pick" value="#58a6ff" aria-label="Fill color">+ </div>+ <div class="lbl">Easing</div>+ <select id="ease-sel">+ <option value="ease-in-out" selected>Ease in-out</option>+ <option value="ease-out">Ease out</option>+ <option value="linear">Linear</option>+ </select>+ <div class="div"></div>+ <div class="lbl">Text</div>+ <input type="text" id="text-inp" value="OUTLINE" maxlength="10">+ <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 fillLayer=document.getElementById('fill-layer');+ const strokeWrap=document.getElementById('stroke-wrap');+ let loopTimer=null;++ const DIR_CLASSES=['dir-down','dir-left','dir-right','dir-center'];++ function applyText(t){+ ['outline-layer','fill-layer','stroke-only','fill-only'].forEach(id=>{+ document.getElementById(id).textContent=t;+ });+ }++ function applyDir(){+ const dir=document.getElementById('dir-sel').value;+ fillLayer.classList.remove(...DIR_CLASSES);+ if(dir!=='up')fillLayer.classList.add('dir-'+dir);+ }++ function reset(){+ fillLayer.classList.remove('filled');+ strokeWrap.classList.remove('filled');+ }++ function play(){+ clearTimeout(loopTimer);+ reset();+ applyDir();+ const dur=+document.getElementById('dur-sl').value;+ requestAnimationFrame(()=>requestAnimationFrame(()=>{+ fillLayer.classList.add('filled');+ strokeWrap.classList.add('filled');+ }));+ if(document.getElementById('loop-tog').checked){+ loopTimer=setTimeout(()=>{reset();setTimeout(play,300);},dur+1400);+ }+ }++ document.getElementById('replay-btn').addEventListener('click',play);+ document.getElementById('dur-sl').addEventListener('input',e=>{+ document.getElementById('dur-v').textContent=e.target.value+'ms';+ document.documentElement.style.setProperty('--fill-dur',e.target.value+'ms');+ });+ document.getElementById('sw-sl').addEventListener('input',e=>{+ document.getElementById('sw-v').textContent=e.target.value+'px';+ document.documentElement.style.setProperty('--stroke-w',e.target.value);+ });+ document.getElementById('stroke-pick').addEventListener('input',e=>{+ document.documentElement.style.setProperty('--stroke-color',e.target.value);+ });+ document.getElementById('fill-pick').addEventListener('input',e=>{+ document.documentElement.style.setProperty('--fill-color',e.target.value);+ });+ document.getElementById('ease-sel').addEventListener('change',e=>{+ document.documentElement.style.setProperty('--fill-ease',e.target.value);+ });+ document.getElementById('dir-sel').addEventListener('change',applyDir);+ document.getElementById('text-inp').addEventListener('input',e=>{+ applyText(e.target.value.toUpperCase()||'OUTLINE');reset();+ });++ play();+</script>+</body>+</html>diff --git a/animations/05-text-typography/rotate-word-carousel/README.md b/animations/05-text-typography/rotate-word-carousel/README.mdnew file mode 100644index 00000000..4e2fd77f--- /dev/null+++ b/animations/05-text-typography/rotate-word-carousel/README.md@@ -0,0 +1,92 @@+# Rotate Word Carousel++## What it is+A rotate word carousel keeps a sentence almost entirely static while cycling one keyword through a list of alternatives. The pattern reads as: "We build [Websites / Apps / Brands / Systems]." Only the bracketed word animates — sliding out as the current word and sliding in as the next. This is the dominant hero headline pattern on agency, freelance, and SaaS landing pages.++## When to use it+- Hero headlines that address multiple audiences: "Built for [Designers / Developers / Teams]"+- Value proposition cycling: "Faster / Simpler / Smarter"+- Service lists: "We build [Websites / Mobile Apps / Design Systems]"+- Any headline where a single dimension varies while the surrounding context is stable++## How it works+The rotating word lives in a container with `overflow: hidden`. The current word slides out in one direction while the next slides in from the opposite:++```html+<h1>+ <span class="static">We build for </span>+ <span class="rotating-container">+ <span class="rotating-word" aria-live="polite">Designers</span>+ </span>+</h1>+```++```css+.rotating-container {+ position: relative;+ display: inline-block;+ overflow: hidden; /* clips words exiting above/below */+ vertical-align: middle;+}++.rotating-word {+ display: block;+ transition: transform 400ms cubic-bezier(.4,0,.2,1), opacity 400ms ease;+}++/* Exit state */+.rotating-word.out-up { transform: translateY(-110%); opacity: 0; }++/* Enter state (transitioning TO default removes this class) */+.rotating-word.enter-below { transform: translateY(110%); opacity: 0; }+```++```js+function transitionWord(container, nextWord) {+ const wordEl = container.querySelector('.rotating-word');+ const duration = 400;++ // Exit current+ wordEl.classList.add('out-up');++ setTimeout(() => {+ wordEl.textContent = nextWord;+ wordEl.classList.remove('out-up');+ wordEl.classList.add('enter-below'); // position below, invisible++ requestAnimationFrame(() => requestAnimationFrame(() => {+ wordEl.classList.remove('enter-below'); // animate to normal position+ }));+ }, duration + 30);+}+```++The auto-cycle:+```js+let i = 0;+const words = ['Designers', 'Developers', 'Humans', 'Teams'];+setInterval(() => {+ transitionWord(container, words[++i % words.length]);+}, holdDuration + transitionDuration * 2);+```++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Hold duration | 2000ms | How long each word stays visible — 1.5–3s is the readable range |+| Transition duration | 400ms | 200ms = snappy; 600ms = deliberate |+| Direction | Up/down | Up = word scrolls up like a slot machine; Left/right = word slides horizontally |+| Color per word | Per-word accent | Unique color per word draws more attention to the change; uniform is calmer |++## Production notes+- **Only one word should rotate**: multiple cycling sections in a single headline create chaos. The static context is what makes the rotating word legible — "We build for [X]" works because "We build for" never changes.+- **Word length variance causes layout shift**: if words have different lengths, the headline reflows on each transition. Solutions: (1) set a fixed `min-width` on the container based on the longest word, (2) use `position: absolute` on the word and manually set container width to the longest word, or (3) choose words of similar length.+- **`aria-live="polite"`**: screen readers will announce each word change after the current utterance completes. Set on the rotating word container, not the entire headline.+- **Keep the word list short**: 4–6 words maximum. Beyond that, users rarely see the full cycle and the repetition becomes numbing. Randomizing the order slightly reduces predictability.+- **GSAP**: `gsap.to(word, { yPercent: -110, opacity: 0, duration: 0.4 })` for exit, then set new text and `gsap.fromTo(word, { yPercent: 110, opacity: 0 }, { yPercent: 0, opacity: 1, duration: 0.4 })` for entry.+- **Typed.js, Motion One**: both have built-in word cycling APIs. Typed.js (`strings: [...]` with `backSpeed`) is the most widely used.++## See also+- [Text Morphing](../text-morphing/) — character-level transitions between words rather than whole-word slides+- [Enter/Exit Typography](../enter-exit-typography/) — full-phrase cycling with enter and exit on the entire headline+- [Typewriter Effect](../typewriter-effect/) — an alternative word-reveal pattern that types characters one by onediff --git a/animations/05-text-typography/rotate-word-carousel/index.html b/animations/05-text-typography/rotate-word-carousel/index.htmlnew file mode 100644index 00000000..276c2e75--- /dev/null+++ b/animations/05-text-typography/rotate-word-carousel/index.html@@ -0,0 +1,186 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Rotate Word Carousel</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--rot-dur:400ms;--hold-dur:2000ms;--rot-ease:cubic-bezier(.4,0,.2,1);--word-color:#58a6ff}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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:32px;overflow:hidden}+ .headline{font-family:Georgia,'Times New Roman',serif;font-size:clamp(22px,3.5vw,42px);line-height:1.3;color:#fff;text-align:center;display:flex;flex-direction:column;align-items:center;gap:0}+ .static-line{display:flex;align-items:center;flex-wrap:wrap;justify-content:center;gap:0.2em}+ .static-text{white-space:nowrap;color:rgba(255,255,255,.75)}+ .rot-container{position:relative;display:inline-block;overflow:hidden;vertical-align:middle}+ .rot-word{+ display:block;+ color:var(--word-color);+ font-style:italic;+ white-space:nowrap;+ will-change:transform,opacity;+ transition:transform var(--rot-dur) var(--rot-ease),opacity var(--rot-dur) ease+ }+ .rot-word.out-up{transform:translateY(-110%);opacity:0}+ .rot-word.out-down{transform:translateY(110%);opacity:0}+ .rot-word.out-left{transform:translateX(-110%);opacity:0}+ .rot-word.out-right{transform:translateX(110%);opacity:0}+ .rot-word.enter-below{transform:translateY(110%);opacity:0}+ .rot-word.enter-above{transform:translateY(-110%);opacity:0}+ .rot-word.enter-left{transform:translateX(-110%);opacity:0}+ .rot-word.enter-right{transform:translateX(110%);opacity:0}+ /* Multi-color classes */+ .wc0{color:#58a6ff}.wc1{color:#56d364}.wc2{color:#d2a8ff}.wc3{color:#ffa657}.wc4{color:#f85149}+ /* Word indicators */+ .word-dots{display:flex;gap:6px;margin-top:16px}+ .word-dot{font-size:9px;padding:3px 8px;border-radius:3px;background:var(--ui-border);color:var(--ui-muted);letter-spacing:0.5px;transition:background .2s,color .2s}+ .word-dot.active{background:var(--ui-accent);color:#000}+ /* 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:monospace;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:monospace;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)}+ textarea{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:88px;line-height:1.5;outline:none}+ textarea:focus{border-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}+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:380px}}+ @media(prefers-reduced-motion:reduce){.rot-word{transition:none!important;transform:none!important;opacity:1!important}}+ </style>+</head>+<body>+<header>+ <h1>Rotate Word Carousel</h1>+ <p>One word cycles through a list while the sentence stays static — the classic hero pattern.</p>+</header>+<div class="layout">+ <div class="stage">+ <div style="display:flex;flex-direction:column;align-items:center">+ <div class="headline" id="headline">+ <div class="static-line">+ <span class="static-text" id="static-text">We craft for</span>+ <div class="rot-container" id="rot-container">+ <span class="rot-word" id="rot-word">Designers</span>+ </div>+ </div>+ </div>+ <div class="word-dots" id="word-dots"></div>+ </div>+ </div>+ <aside>+ <p class="note">Only ONE word rotates — the sentence is static. Keep words similar in length to minimize layout shift. aria-live announces each new word to screen readers.</p>+ <div class="lbl">Hold Duration</div>+ <div class="sr"><input type="range" id="hold-sl" min="1000" max="5000" value="2000" step="100"><span class="sv" id="hold-v">2.0s</span></div>+ <div class="lbl">Transition Duration</div>+ <div class="sr"><input type="range" id="dur-sl" min="200" max="800" value="400" step="50"><span class="sv" id="dur-v">400ms</span></div>+ <div class="lbl">Direction</div>+ <select id="dir-sel">+ <option value="up" selected>Up</option>+ <option value="down">Down</option>+ <option value="left">Left</option>+ <option value="right">Right</option>+ </select>+ <label class="tog"><input type="checkbox" id="color-tog" checked><span>Different color per word</span></label>+ <div class="div"></div>+ <div class="lbl">Static text</div>+ <input type="text" id="static-inp" value="We craft for">+ <div class="lbl">Rotating words</div>+ <textarea id="words-inp">Designers+Developers+Humans+Teams+Startups</textarea>+ <button class="rst" id="restart-btn">↺ Restart</button>+ </aside>+</div>+<script>+ let wordIdx=0,timer=null;+ const rotWord=document.getElementById('rot-word');+ const rotContainer=document.getElementById('rot-container');+ const staticText=document.getElementById('static-text');+ const dotsEl=document.getElementById('word-dots');++ function getWords(){return document.getElementById('words-inp').value.split('\n').map(w=>w.trim()).filter(Boolean)}+ function getDur(){return+document.getElementById('dur-sl').value}+ function getHold(){return+document.getElementById('hold-sl').value}+ function getDir(){return document.getElementById('dir-sel').value}+ const COLORS=['wc0','wc1','wc2','wc3','wc4'];+ const outClasses=['out-up','out-down','out-left','out-right'];+ const enterClasses=['enter-below','enter-above','enter-left','enter-right'];++ function buildDots(words){+ dotsEl.innerHTML='';+ words.forEach((w,i)=>{const d=document.createElement('div');d.className='word-dot'+(i===wordIdx?' active':'');d.textContent=w;dotsEl.appendChild(d);});+ }+ function updateDots(i){dotsEl.querySelectorAll('.word-dot').forEach((d,j)=>d.classList.toggle('active',j===i));}++ function setColor(el,i){+ el.classList.remove(...COLORS);+ if(document.getElementById('color-tog').checked)el.classList.add(COLORS[i%COLORS.length]);+ else el.style.color='var(--word-color)';+ }++ function transitionTo(nextWord,nextIdx,done){+ const dir=getDir();+ const outMap={up:'out-up',down:'out-down',left:'out-left',right:'out-right'};+ const enterMap={up:'enter-below',down:'enter-above',left:'enter-right',right:'enter-left'};+ rotWord.classList.add(outMap[dir]);+ setTimeout(()=>{+ // swap word+ rotWord.textContent=nextWord;+ setColor(rotWord,nextIdx);+ rotWord.classList.remove(...outClasses,...enterClasses);+ rotWord.classList.add(enterMap[dir]);+ // size container to new word+ requestAnimationFrame(()=>requestAnimationFrame(()=>{+ rotWord.classList.remove(...enterClasses);+ setTimeout(done,getDur()+50);+ }));+ },getDur()+30);+ }++ function cycle(){+ const words=getWords();if(words.length<2)return;+ const next=(wordIdx+1)%words.length;+ transitionTo(words[next],next,()=>{+ wordIdx=next;updateDots(wordIdx);+ timer=setTimeout(cycle,getHold());+ });+ }++ function start(){+ if(timer)clearTimeout(timer);wordIdx=0;+ const words=getWords();if(!words.length)return;+ rotWord.classList.remove(...outClasses,...enterClasses);+ rotWord.textContent=words[0];+ setColor(rotWord,0);+ staticText.textContent=document.getElementById('static-inp').value;+ buildDots(words);+ timer=setTimeout(cycle,getHold());+ }++ document.getElementById('restart-btn').addEventListener('click',start);+ document.getElementById('static-inp').addEventListener('input',e=>{staticText.textContent=e.target.value});+ document.getElementById('words-inp').addEventListener('change',start);+ document.getElementById('hold-sl').addEventListener('input',e=>{document.getElementById('hold-v').textContent=(e.target.value/1000).toFixed(1)+'s'});+ document.getElementById('dur-sl').addEventListener('input',e=>{document.getElementById('dur-v').textContent=e.target.value+'ms'});+ document.getElementById('dir-sel').addEventListener('change',()=>{});+ document.getElementById('color-tog').addEventListener('change',()=>setColor(rotWord,wordIdx));++ rotWord.setAttribute('aria-live','polite');+ start();+</script>+</body>+</html>diff --git a/animations/05-text-typography/scramble-text/README.md b/animations/05-text-typography/scramble-text/README.mdnew file mode 100644index 00000000..118be801--- /dev/null+++ b/animations/05-text-typography/scramble-text/README.md@@ -0,0 +1,71 @@+# 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.++## When to use it+- Tech products, cybersecurity tools, and developer-facing sites+- Dramatic hero headline reveals where text "decodes" on page load+- Hover effects on navigation items or interactive cards+- Loading screens that need a purposeful aesthetic while content loads++## How it works+Each character of the target string gets its own `<span>`. A `setInterval` loop replaces unlocked spans with random characters. Each character has a staggered `setTimeout` that locks it to the correct value after a delay:++```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;+ });++ // Settle each character after a staggered delay+ spans.forEach((s, i) => {+ if (!s) return;+ setTimeout(() => {+ s.textContent = targetText[i];+ locked[i] = true;+ if (++lockedCount === spans.filter(Boolean).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)];+ });+ }, cycleMs);++ // Clear interval once all locked+ function onDone() { clearInterval(interval); }+}+```++## 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 |++## 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.+- **Character set choice matters**: symbols (`!@#$%`) evoke hacking; katakana evokes The Matrix; mixed uppercase/numeric evokes cryptography. Match the set to the aesthetic of your product.+- **Don't overuse**: every headline scrambling on every page transition becomes visual noise. Reserve for hero moments — one word or phrase that deserves a dramatic entrance.+- **Uppercase works better**: lowercase letters with descenders (g, j, p, q, y) look awkward scrambling through uppercase symbols. UPPERCASE text is cleaner.+- **GSAP TextPlugin**: handles scramble-style effects with configurable `chars` parameter. Simpler API for production use. `gsap.to(el, { duration: 1, scrambleText: { text: "HELLO", chars: "lowerCase" } })`.+- **`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 alternativediff --git a/animations/05-text-typography/scramble-text/index.html b/animations/05-text-typography/scramble-text/index.htmlnew file mode 100644index 00000000..87f2d8fe--- /dev/null+++ b/animations/05-text-typography/scramble-text/index.html@@ -0,0 +1,157 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Scramble / Glitch Text</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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}+ .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:monospace;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:monospace;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:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @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{height:auto;min-height:360px}}+ @media(prefers-reduced-motion:reduce){.scramble-text .char{transition:none!important;color:#fff!important}}+ </style>+</head>+<body>+<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>+ <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>+ </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,running=false;+const out=document.getElementById('scramble-out');+const lockedCt=document.getElementById('locked-ct');+const remainCt=document.getElementById('remain-ct');+const cycleCt=document.getElementById('cycle-ct');++function randChar(charset){return charset[Math.floor(Math.random()*charset.length)]}++function scramble(){+ if(cycleTimer)clearInterval(cycleTimer);+ running=true;+ const text=document.getElementById('text-inp').value.toUpperCase();+ const charset=CHARSETS[document.getElementById('charset-sel').value];+ const cycleMs=+document.getElementById('cyc-sl').value;+ const settleMs=+document.getElementById('settle-sl').value;+ cycleCt.textContent=cycleMs+'ms';++ // Build span per char+ out.innerHTML='';+ const spans=[];+ text.split('').forEach(c=>{+ 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='char scrambling';s.textContent=randChar(charset);out.appendChild(s);spans.push(s);+ });+ out.setAttribute('aria-label','Loading: '+text);++ const locked=new Array(text.length).fill(false);+ let lockedCount=0;++ // Settle each char after staggered delay+ spans.forEach((s,i)=>{+ if(!s)return;+ setTimeout(()=>{+ s.textContent=text[i];s.classList.remove('scrambling');s.classList.add('locked');+ locked[i]=true;lockedCount++;+ lockedCt.textContent=lockedCount;+ remainCt.textContent=spans.filter(Boolean).length-lockedCount;+ if(lockedCount===spans.filter(Boolean).length){+ running=false;out.setAttribute('aria-label',text);+ if(document.getElementById('loop-tog').checked)setTimeout(scramble,1200);+ }+ },settleMs*i+settleMs);+ });++ // Cycle random chars on unlocked positions+ cycleTimer=setInterval(()=>{+ spans.forEach((s,i)=>{if(s&&!locked[i])s.textContent=randChar(charset);});+ },cycleMs);++ const total=spans.filter(Boolean).length;+ const totalTime=settleMs*total+settleMs;+ setTimeout(()=>clearInterval(cycleTimer),totalTime+cycleMs*2);++ remainCt.textContent=total;lockedCt.textContent='0';+}++document.getElementById('replay-btn').addEventListener('click',()=>{+ clearInterval(cycleTimer);running=false;scramble();+});+document.getElementById('cyc-sl').addEventListener('input',e=>document.getElementById('cyc-v').textContent=e.target.value+'ms');+document.getElementById('settle-sl').addEventListener('input',e=>document.getElementById('settle-v').textContent=e.target.value+'ms');+document.getElementById('text-inp').addEventListener('keydown',e=>{if(e.key==='Enter')scramble()});++scramble();+</script>+</body>+</html>diff --git a/animations/05-text-typography/text-clip-path-reveal/README.md b/animations/05-text-typography/text-clip-path-reveal/README.mdnew file mode 100644index 00000000..0619a702--- /dev/null+++ b/animations/05-text-typography/text-clip-path-reveal/README.md@@ -0,0 +1,72 @@+# Text Clip-Path Reveal++## What it is+A text clip-path reveal conceals a fully-rendered headline behind a mask and progressively expands that mask to uncover the text. The text is laid out at full quality from the first frame — kerning, ligatures, and spacing are all computed before the animation starts. Only visibility changes, never the text itself. This makes it superior to character-stagger approaches for preserving typographic precision.++## When to use it+- Multi-line display headlines that should read as a single composed unit+- Taglines where the typographer's exact spacing must be preserved+- Photography or design portfolios where the type quality is part of the brand+- Any heading where character-by-character stagger would disrupt the reading of the whole phrase++## How it works+Each line is wrapped in a container with `overflow: hidden`. The text element starts with a `clip-path` that hides it entirely, then transitions to fully visible:++```css+:root {+ --line-dur: 700ms;+ --ease: ease-out;+}++.line-text {+ display: block;+ clip-path: inset(0 100% 0 0); /* hidden: 100% clipped from right */+ transition: clip-path var(--line-dur) var(--ease);+}++.line-text.revealed {+ clip-path: inset(0 0% 0 0); /* visible: nothing clipped */+}+```++Lines are staggered by adding a CSS `transition-delay` based on line index, or by applying the class with a `setTimeout` offset in JavaScript:++```js+lines.forEach((span, i) => {+ setTimeout(() => span.classList.add('revealed'), stagger * i);+});+```++**Direction variants** use different initial clip-path values:+```css+/* Left-to-right (default) */+.ltr { clip-path: inset(0 100% 0 0); }++/* Right-to-left */+.rtl { clip-path: inset(0 0 0 100%); }++/* Top-to-bottom */+.ttb { clip-path: inset(0 0 100% 0); }+```++All resolve to `inset(0 0% 0 0)` when revealed — a single `.revealed` class handles all directions.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Line duration | 700ms | 300ms = snappy swipe; 1200ms = cinematic wipe |+| Stagger | 180ms | Gap between lines starting — 100–200ms feels like a natural cascade |+| Easing | ease-out | Deceleration makes the reveal feel physical; linear feels mechanical |+| Direction | Left→Right | Matches reading direction; RTL matches RTL scripts; TTB works for display headers |++## Production notes+- **No layout shift**: unlike character stagger, clip-path reveal has zero impact on layout — the text is always in its final position, just hidden. This means no reflows and no risk of line-break changes mid-animation.+- **`overflow: hidden` not required**: unlike `translate`-based reveals that need overflow clipping, `clip-path` is self-contained. No parent overflow manipulation needed.+- **SVG clip-path for complex shapes**: CSS `inset()` and `circle()` cover most cases. For shaped reveals (diagonal wipes, irregular masks), use an SVG `<clipPath>` element. The principle is identical; only the mask shape changes.+- **GSAP**: `gsap.from(lines, { clipPath: 'inset(0 100% 0 0)', duration: 0.7, stagger: 0.18, ease: 'power2.out' })`. Clean one-liner, no class toggling.+- **Intersection Observer pairing**: in production, trigger the reveal when the headline scrolls into view using `IntersectionObserver`. The demo triggers on load/replay; combine with the [Reveal on Scroll](../../01-scroll-based/reveal-on-scroll/) pattern for scroll-triggered variants.++## See also+- [Clip-Path Reveal](../../02-entrance-and-exit/clip-path-reveal/) — the same technique applied to arbitrary elements, not specifically text+- [Curtain Reveal](../../02-entrance-and-exit/curtain-reveal/) — a colored overlay slides over then off, instead of unmasking the element directly+- [Enter/Exit Typography](../enter-exit-typography/) — clip reveal as one of several possible enter choreographiesdiff --git a/animations/05-text-typography/text-clip-path-reveal/index.html b/animations/05-text-typography/text-clip-path-reveal/index.htmlnew file mode 100644index 00000000..9b23d13a--- /dev/null+++ b/animations/05-text-typography/text-clip-path-reveal/index.html@@ -0,0 +1,141 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Text Clip-Path Reveal</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--line-dur:700ms;--stagger:180ms;--ease:ease-out}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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)}+ .headline{display:flex;flex-direction:column;gap:4px;overflow:visible}+ .line-wrap{overflow:hidden;line-height:1.15}+ .line-text{+ font-family:Georgia,'Times New Roman',serif;+ font-size:clamp(36px,6vw,72px);+ font-style:italic;+ line-height:1.15;+ color:#fff;+ display:block;+ clip-path:inset(0 100% 0 0);+ transition:clip-path var(--line-dur) var(--ease)+ }+ .line-text.dir-rtl{clip-path:inset(0 0 0 100%)}+ .line-text.dir-ttb{clip-path:inset(0 0 100% 0)}+ .line-text.revealed{clip-path:inset(0 0% 0 0)!important}+ /* 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:monospace;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:monospace;font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:72px;line-height:1.5;outline:none}+ textarea:focus{border-color:var(--ui-accent)}+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @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{height:auto;min-height:360px}}+ @media(prefers-reduced-motion:reduce){.line-text{clip-path:inset(0)!important;transition:none!important}}+ </style>+</head>+<body>+<header>+ <h1>Text Clip-Path Reveal</h1>+ <p>Headline reveals line-by-line via an expanding clip-path mask — preserves kerning and spacing perfectly.</p>+</header>+<div class="layout">+ <div class="stage">+ <div class="headline" id="headline" aria-live="polite"></div>+ </div>+ <aside>+ <p class="note">clip-path reveal preserves typographic quality — the text is fully laid out from the start, only progressively visible. Character-stagger methods can disrupt kerning.</p>+ <div class="lbl">Direction</div>+ <select id="dir-sel">+ <option value="ltr" selected>Left → Right</option>+ <option value="rtl">Right → Left</option>+ <option value="ttb">Top → Bottom</option>+ </select>+ <div class="lbl">Line Duration</div>+ <div class="sr"><input type="range" id="dur-sl" min="300" max="1200" value="700" step="50"><span class="sv" id="dur-v">700ms</span></div>+ <div class="lbl">Stagger Between Lines</div>+ <div class="sr"><input type="range" id="stag-sl" min="80" max="400" value="180" step="20"><span class="sv" id="stag-v">180ms</span></div>+ <div class="lbl">Easing</div>+ <select id="ease-sel">+ <option value="ease-out" selected>Ease out</option>+ <option value="ease-in-out">Ease in-out</option>+ <option value="linear">Linear</option>+ <option value="cubic-bezier(.2,.7,.3,1)">Smooth</option>+ </select>+ <div class="div"></div>+ <div class="lbl">Lines (one per line)</div>+ <textarea id="lines-inp">Good design+Is honest+Always.</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>+<script>+ const headline=document.getElementById('headline');+ let loopTimer=null;++ function getDir(){return document.getElementById('dir-sel').value}+ function getDirClass(dir){+ if(dir==='rtl')return 'dir-rtl';+ if(dir==='ttb')return 'dir-ttb';+ return '';+ }++ function buildLines(){+ const text=document.getElementById('lines-inp').value;+ const lines=text.split('\n').filter(l=>l.trim());+ headline.innerHTML='';+ return lines.map(line=>{+ const wrap=document.createElement('div');wrap.className='line-wrap';+ const span=document.createElement('span');span.className='line-text';+ const dir=getDir();+ if(dir!=='ltr')span.classList.add(getDirClass(dir));+ span.textContent=line;+ wrap.appendChild(span);headline.appendChild(wrap);+ return span;+ });+ }++ function reveal(){+ if(loopTimer)clearTimeout(loopTimer);+ const dur=+document.getElementById('dur-sl').value;+ const stag=+document.getElementById('stag-sl').value;+ document.documentElement.style.setProperty('--line-dur',dur+'ms');+ document.documentElement.style.setProperty('--stagger',stag+'ms');+ document.documentElement.style.setProperty('--ease',document.getElementById('ease-sel').value);++ const lines=buildLines();+ lines.forEach((span,i)=>{+ setTimeout(()=>{span.classList.add('revealed');},50+stag*i);+ });++ if(document.getElementById('loop-tog').checked){+ const total=50+stag*(lines.length-1)+dur+1200;+ loopTimer=setTimeout(reveal,total);+ }+ }++ document.getElementById('replay-btn').addEventListener('click',reveal);+ document.getElementById('dur-sl').addEventListener('input',e=>document.getElementById('dur-v').textContent=e.target.value+'ms');+ document.getElementById('stag-sl').addEventListener('input',e=>document.getElementById('stag-v').textContent=e.target.value+'ms');+ document.getElementById('dir-sel').addEventListener('change',reveal);+ document.getElementById('ease-sel').addEventListener('change',reveal);++ reveal();+</script>+</body>+</html>diff --git a/animations/05-text-typography/text-gradient-animation/README.md b/animations/05-text-typography/text-gradient-animation/README.mdnew file mode 100644index 00000000..e68d6245--- /dev/null+++ b/animations/05-text-typography/text-gradient-animation/README.md@@ -0,0 +1,76 @@+# Text Gradient Animation++## What it is+Text gradient animation flows color through the characters of a text element. The two required CSS properties are `background-clip: text` and `color: transparent` — these expose the element's background image through the character shapes. Animating `background-position` then moves the gradient behind the stationary text, creating the appearance of color flowing through the letters. The text itself never moves.++## When to use it+- Display headlines on creative, tech, and brand sites+- Logo animations and wordmarks+- Status text that indicates an active or loading state via color cycling+- Decorative display type that needs visual richness without imagery++## How it works+Two CSS properties expose the background through text shapes, then a keyframe animation moves the background:++```css+.gradient-text {+ /* The trick: two properties working together */+ background-clip: text;+ -webkit-background-clip: text;+ color: transparent;++ /* The gradient to animate */+ background-image: linear-gradient(90deg, #58a6ff, #56d364, #d2a8ff, #ffa657, #58a6ff);+ background-size: 300% 100%;+ animation: flow 4s linear infinite;+}++@keyframes flow {+ from { background-position: 0% 50%; }+ to { background-position: 300% 50%; }+}+```++The `background-size: 300%` makes the gradient wider than the element, so scrolling `background-position` shows different color sections. The last color stop matches the first, creating a seamless loop.++For a conic gradient (rotating color wheel):++```css+.conic-text {+ background-image: conic-gradient(from 0deg, #58a6ff, #56d364, #d2a8ff, #ffa657, #58a6ff);+ background-size: 200% 200%;+ background-position: 50% 50%;+ animation: spin 4s linear infinite;+}++@keyframes spin {+ from { background-position: 0% 0%; }+ to { background-position: 100% 100%; }+}+```++For live JavaScript control (e.g., mouse position driving gradient angle):++```js+el.style.backgroundImage = `linear-gradient(${angle}deg, ${c1}, ${c2})`;+```++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Animation duration | 4s | Slower = more subtle and ambient; faster = more energetic |+| `background-size` | 300% | Larger = wider gradient, softer transitions; smaller = more color change per pixel |+| Color stops | 4–5 | More stops = richer; repeat first stop at end to loop seamlessly |+| Gradient type | Linear | Conic creates a rotation effect; radial creates a pulsing center |++## Production notes+- **`-webkit-background-clip: text`**: the non-prefixed `background-clip: text` is now widely supported (Chrome 119+, Firefox 122+, Safari 14+), but the `-webkit-` prefix is still required for Safari compatibility across all versions. Include both.+- **`color: transparent` is required**: `background-clip: text` clips the background to the text shape, but the text color still renders on top. Without `color: transparent`, the gradient is hidden beneath solid text color.+- **Performance**: `background-position` animation does not use the CSS compositor and triggers paint on each frame. For long-running animations on large text, test performance on mid-range devices. `@keyframes` (vs. JS `requestAnimationFrame`) avoids the main thread.+- **Fallback**: set a solid `color` on the element before the gradient properties. Browsers that don't support `background-clip: text` will show solid-color text rather than invisible text.+- **Selection color**: selected text with `color: transparent` may render without a visible selection highlight in some browsers. Test selection behavior and add `::selection { color: white; background: blue; }` if needed.++## See also+- [Variable Font Morph](../variable-font-morph/) — another CSS-only text animation, morphing font axes rather than color+- [Outline to Fill](../outline-to-fill/) — color appearing inside text characters via a different mechanism (clip-path reveal)+- [Kinetic Typography](../kinetic-typography/) — gradient text as one technique within a broader motion sequencediff --git a/animations/05-text-typography/text-gradient-animation/index.html b/animations/05-text-typography/text-gradient-animation/index.htmlnew file mode 100644index 00000000..42edc71c--- /dev/null+++ b/animations/05-text-typography/text-gradient-animation/index.html@@ -0,0 +1,128 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Text Gradient Animation</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--grad-dur:4s;--grad-size:120px}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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}+ /* Gradient text base */+ .grad-text{+ font-family:Georgia,'Times New Roman',serif;+ font-size:var(--grad-size);+ font-style:italic;+ line-height:1;+ letter-spacing:-0.02em;+ background-clip:text;+ -webkit-background-clip:text;+ color:transparent;+ background-size:300% 300%;+ animation:grad-flow var(--grad-dur) linear infinite;+ display:block;+ text-align:center;+ -webkit-user-select:none;user-select:none+ }+ /* Linear */+ .grad-linear{background-image:linear-gradient(90deg,#58a6ff,#56d364,#d2a8ff,#ffa657,#58a6ff)}+ /* Conic */+ .grad-conic{+ background-image:conic-gradient(from 0deg,#58a6ff,#56d364,#d2a8ff,#ffa657,#58a6ff);+ animation:grad-spin var(--grad-dur) linear infinite;+ background-size:200% 200%;background-position:50% 50%+ }+ /* Multi-stop */+ .grad-multi{background-image:linear-gradient(135deg,#f85149,#ffa657,#56d364,#58a6ff,#d2a8ff,#f85149)}+ /* Custom two-color */+ .grad-custom{background-image:linear-gradient(90deg,var(--c1,#58a6ff),var(--c2,#d2a8ff),var(--c1,#58a6ff))}+ @keyframes grad-flow{from{background-position:0% 50%}to{background-position:300% 50%}}+ @keyframes grad-spin{from{background-position:0% 0%}to{background-position:100% 100%}}+ .grad-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted)}+ /* 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:monospace;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:monospace;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)}+ .color-row{display:flex;gap:8px;align-items:center;font-size:10px;color:var(--ui-muted)}+ input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}:root{--grad-size:64px}}+ @media(prefers-reduced-motion:reduce){.grad-text{animation:none!important;background-position:0% 50%!important}}+ </style>+</head>+<body>+<header>+ <h1>Text Gradient Animation</h1>+ <p>background-clip: text + animated background-position flows color through the characters.</p>+</header>+<div class="layout">+ <div class="stage">+ <div class="grad-label">Gradient</div>+ <div class="grad-text grad-linear" id="grad-text">Flow</div>+ <div class="grad-label" style="opacity:.4;font-size:9px">background-clip: text · color: transparent</div>+ </div>+ <aside>+ <p class="note">The text never animates — only the gradient behind it moves. background-clip: text + color: transparent exposes the background through character shapes.</p>+ <div class="lbl">Gradient Type</div>+ <select id="type-sel">+ <option value="grad-linear" selected>Linear flow</option>+ <option value="grad-conic">Conic rotation</option>+ <option value="grad-multi">Multi-stop 135°</option>+ <option value="grad-custom">Two-color custom</option>+ </select>+ <div class="lbl">Speed</div>+ <div class="sr"><input type="range" id="spd-sl" min="10" max="100" value="40" step="5"><span class="sv" id="spd-v">4s</span></div>+ <div class="lbl">Font Size</div>+ <div class="sr"><input type="range" id="size-sl" min="32" max="160" value="120" step="8"><span class="sv" id="size-v">120px</span></div>+ <div class="lbl">Custom Colors</div>+ <div class="color-row">+ <span>Start</span>+ <input type="color" id="c1-pick" value="#58a6ff" aria-label="Start color">+ <span>End</span>+ <input type="color" id="c2-pick" value="#d2a8ff" aria-label="End color">+ </div>+ <div class="div"></div>+ <div class="lbl">Text</div>+ <input type="text" id="text-inp" value="Flow">+ </aside>+</div>+<script>+ const gradText=document.getElementById('grad-text');+ const CLASSES=['grad-linear','grad-conic','grad-multi','grad-custom'];++ document.getElementById('type-sel').addEventListener('change',e=>{+ gradText.classList.remove(...CLASSES);+ gradText.classList.add(e.target.value);+ });+ document.getElementById('spd-sl').addEventListener('input',e=>{+ const v=e.target.value/10;+ document.getElementById('spd-v').textContent=v.toFixed(1)+'s';+ document.documentElement.style.setProperty('--grad-dur',v+'s');+ });+ document.getElementById('size-sl').addEventListener('input',e=>{+ document.getElementById('size-v').textContent=e.target.value+'px';+ document.documentElement.style.setProperty('--grad-size',e.target.value+'px');+ });+ document.getElementById('text-inp').addEventListener('input',e=>{+ gradText.textContent=e.target.value||'Flow';+ });+ document.getElementById('c1-pick').addEventListener('input',e=>{+ document.documentElement.style.setProperty('--c1',e.target.value);+ });+ document.getElementById('c2-pick').addEventListener('input',e=>{+ document.documentElement.style.setProperty('--c2',e.target.value);+ });+</script>+</body>+</html>diff --git a/animations/05-text-typography/text-morphing/README.md b/animations/05-text-typography/text-morphing/README.mdnew file mode 100644index 00000000..a6f33703--- /dev/null+++ b/animations/05-text-typography/text-morphing/README.md@@ -0,0 +1,82 @@+# Text Morphing++## What it is+Text morphing transitions one word into another by animating individual characters out and new characters in. Each character slides out in one direction while its replacement slides in from the opposite direction, with staggered delays creating a wave-like effect across the word. When words have different lengths, extra characters appear or disappear independently.++## When to use it+- A single changing word in a static phrase: "We make [websites / apps / brands]"+- Animated state transitions where a label changes meaning: "Loading → Ready → Error"+- Thematic cycling between related concepts: OCEAN → RIVER → STREAM+- Any UI element where a text value changes and the change should feel connected rather than abrupt++## How it works+Each character occupies its own `<span>`. When transitioning from word A to word B, the outgoing spans receive an exit class, and after a delay equal to the exit duration, the incoming spans are built and their enter class is removed to trigger the CSS transition:++```js+function morphTo(container, toWord, dir = 'up') {+ const duration = 400;+ const fromChars = [...container.querySelectorAll('.char')];++ // Exit current characters+ fromChars.forEach((c, i) => {+ c.style.transitionDelay = i * 30 + 'ms'; // stagger+ c.classList.add('out-' + dir);+ });++ setTimeout(() => {+ container.innerHTML = '';++ // Build incoming characters in off-screen position+ const enterClass = { up:'enter-below', down:'enter-above',+ left:'enter-right', right:'enter-left' }[dir];+ const spans = [...toWord].map(c => {+ const s = document.createElement('span');+ s.className = 'char ' + enterClass;+ s.textContent = c;+ container.appendChild(s);+ return s;+ });++ // Double rAF ensures browser painted the off-screen position before transitioning+ requestAnimationFrame(() => requestAnimationFrame(() => {+ spans.forEach((s, i) => {+ s.style.transitionDelay = i * 30 + 'ms';+ s.classList.remove(enterClass); // transition to normal position+ });+ }));+ }, duration + fromChars.length * 30 + 60);+}+```++```css+.char {+ display: inline-block;+ transition: transform 400ms cubic-bezier(.4,0,.2,1), opacity 400ms ease;+}++.out-up { transform: translateY(-110%); opacity: 0; }+.out-down { transform: translateY( 110%); opacity: 0; }++.enter-below { transform: translateY( 110%); opacity: 0; }+.enter-above { transform: translateY(-110%); opacity: 0; }+```++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Morph duration | 400ms | Per-character animation time — 200ms feels snappy, 600ms feels cinematic |+| Stagger per char | 0–80ms | 0 = all chars move simultaneously; 40–60ms creates a readable wave |+| Pause between words | 1500ms | How long each word holds before the next morph — must be long enough to read |+| Direction | Up | Up/down for carousel-style; left/right for slide-style; pick one and stay consistent |++## Production notes+- **Length mismatch**: when word A has 5 chars and word B has 8, the extra 3 chars need to fade in from nothing. When B is shorter, 3 chars of A must disappear. The simplest approach: extra chars exit/enter with a 0-width transition or opacity-only fade, so they don't affect the layout of surrounding characters.+- **Fixed-width container**: to prevent layout shift as word length changes, give the rotating word container a fixed or `min-width` based on the longest word. Otherwise sibling elements jump as words swap.+- **`will-change: transform`**: only add this during active morphing — set it at the start of a transition and remove it after. Persistent `will-change` on many small spans wastes GPU memory.+- **GSAP**: `gsap.to(chars, { y: -50, opacity: 0, stagger: 0.03, duration: 0.4 })` for exits, then rebuild and animate in. GSAP's stagger model is cleaner than per-element `transitionDelay` in JavaScript.+- **SplitType**: a lightweight library that splits text into `<div>` wrappers per word/char without the overhead of GSAP. Pairs well with this pattern.++## See also+- [Rotate Word Carousel](../rotate-word-carousel/) — the same concept with a simpler whole-word slide (no character splitting)+- [Scramble / Glitch Text](../scramble-text/) — random characters before settling, rather than a directional transition+- [Typewriter Effect](../typewriter-effect/) — character-by-character reveal in reading orderdiff --git a/animations/05-text-typography/text-morphing/index.html b/animations/05-text-typography/text-morphing/index.htmlnew file mode 100644index 00000000..d505c8ba--- /dev/null+++ b/animations/05-text-typography/text-morphing/index.html@@ -0,0 +1,200 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Text Morphing</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--morph-dur:400ms;--pause-dur:1500ms;--stagger:0ms}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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:20px;padding:32px}+ .morph-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted)}+ /* Word display area */+ .morph-stage{height:clamp(80px,12vw,130px);display:flex;align-items:center;justify-content:center;overflow:visible;position:relative;min-width:200px}+ .morph-word{position:absolute;display:flex;align-items:center;gap:0;top:50%;transform:translateY(-50%)}+ .morph-char{+ font-family:Georgia,'Times New Roman',serif;+ font-size:clamp(56px,9vw,100px);+ line-height:1;+ color:#fff;+ display:inline-block;+ will-change:transform,opacity;+ transition:transform var(--morph-dur) cubic-bezier(.4,0,.2,1),opacity var(--morph-dur) ease+ }+ .morph-char.out-up{transform:translateY(-100%);opacity:0}+ .morph-char.out-down{transform:translateY(100%);opacity:0}+ .morph-char.out-left{transform:translateX(-80%);opacity:0}+ .morph-char.out-right{transform:translateX(80%);opacity:0}+ .morph-char.enter-from-below{transform:translateY(100%);opacity:0}+ .morph-char.enter-from-above{transform:translateY(-100%);opacity:0}+ .morph-char.enter-from-left{transform:translateX(-80%);opacity:0}+ .morph-char.enter-from-right{transform:translateX(80%);opacity:0}+ /* Word cycle indicator */+ .cycle-dots{display:flex;gap:6px}+ .cycle-dot{width:6px;height:6px;border-radius:50%;background:var(--ui-border);transition:background .2s}+ .cycle-dot.active{background:var(--ui-accent)}+ /* 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)}+ .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: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:monospace;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:monospace;font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:88px;line-height:1.5;outline:none}+ textarea:focus{border-color:var(--ui-accent)}+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}}+ @media(prefers-reduced-motion:reduce){.morph-char{transition:none!important;transform:none!important;opacity:1!important}}+ </style>+</head>+<body>+<header>+ <h1>Text Morphing</h1>+ <p>One word transitions into another character-by-character — each letter slides out as the next slides in.</p>+</header>+<div class="layout">+ <div class="stage">+ <div class="morph-label">Morphing</div>+ <div class="morph-stage" id="morph-stage" aria-live="polite">+ <div class="morph-word" id="current-word"></div>+ </div>+ <div class="cycle-dots" id="dots"></div>+ </div>+ <aside>+ <p class="note">For words of different lengths, extra characters fade independently. Keep word lengths similar to minimize the layout shift during transition.</p>+ <div class="lbl">Morph Duration</div>+ <div class="sr"><input type="range" id="dur-sl" min="200" max="800" value="400" step="50"><span class="sv" id="dur-v">400ms</span></div>+ <div class="lbl">Pause Between Words</div>+ <div class="sr"><input type="range" id="pause-sl" min="500" max="4000" value="1500" step="100"><span class="sv" id="pause-v">1.5s</span></div>+ <div class="lbl">Stagger Per Char</div>+ <div class="sr"><input type="range" id="stag-sl" min="0" max="80" value="0" step="5"><span class="sv" id="stag-v">0ms</span></div>+ <div class="lbl">Direction</div>+ <select id="dir-sel">+ <option value="up" selected>Up</option>+ <option value="down">Down</option>+ <option value="left">Left</option>+ <option value="right">Right</option>+ </select>+ <div class="div"></div>+ <div class="lbl">Words (one per line)</div>+ <textarea id="words-inp">OCEAN+RIVER+STORM+LIGHT+SOUND</textarea>+ <button class="rst" id="restart-btn">↺ Restart</button>+ <div class="kv"><span>Current word</span><span class="v" id="cur-word-kv">—</span></div>+ </aside>+</div>+<script>+ let wordIdx=0,morphTimer=null,running=false;+ const wordEl=document.getElementById('current-word');+ const dotsEl=document.getElementById('dots');+ const curWordKv=document.getElementById('cur-word-kv');++ function getWords(){+ return document.getElementById('words-inp').value.split('\n').map(w=>w.trim().toUpperCase()).filter(Boolean);+ }+ function getDur(){return+document.getElementById('dur-sl').value}+ function getPause(){return+document.getElementById('pause-sl').value}+ function getStag(){return+document.getElementById('stag-sl').value}+ function getDir(){return document.getElementById('dir-sel').value}++ function buildDots(words){+ dotsEl.innerHTML='';+ words.forEach((_,i)=>{+ const d=document.createElement('div');d.className='cycle-dot'+(i===wordIdx?' active':'');+ dotsEl.appendChild(d);+ });+ }+ function updateDots(i){+ dotsEl.querySelectorAll('.cycle-dot').forEach((d,j)=>d.classList.toggle('active',j===i));+ }++ function showWord(word){+ wordEl.innerHTML='';+ word.split('').forEach((c,i)=>{+ const s=document.createElement('span');s.className='morph-char';s.textContent=c;+ const stag=getStag();+ if(stag>0)s.style.transitionDelay=(stag*i)+'ms';+ wordEl.appendChild(s);+ });+ }++ function morphTo(fromWord,toWord,done){+ const dir=getDir();+ const dur=getDur();+ const stag=getStag();+ const fromChars=[...wordEl.querySelectorAll('.morph-char')];+ const outClass='out-'+dir;++ // Exit current word+ fromChars.forEach((c,i)=>{+ if(stag>0)c.style.transitionDelay=(stag*i)+'ms';+ else c.style.transitionDelay='0ms';+ c.classList.add(outClass);+ });++ const exitDur=dur+(stag*(fromChars.length-1));+ setTimeout(()=>{+ // Build new word off-screen+ wordEl.innerHTML='';+ const enterDir={up:'enter-from-below',down:'enter-from-above',left:'enter-from-right',right:'enter-from-left'}[dir];+ const toChars=[];+ toWord.split('').forEach((c,i)=>{+ const s=document.createElement('span');s.className='morph-char '+enterDir;+ if(stag>0)s.style.transitionDelay=(stag*i)+'ms';+ s.textContent=c;wordEl.appendChild(s);toChars.push(s);+ });+ // Animate in+ requestAnimationFrame(()=>requestAnimationFrame(()=>{+ toChars.forEach(c=>{c.classList.remove('enter-from-below','enter-from-above','enter-from-left','enter-from-right');});+ const enterDur=dur+(stag*(toChars.length-1));+ setTimeout(done,enterDur+50);+ }));+ },exitDur+60);+ }++ function cycle(){+ const words=getWords();+ if(words.length<2)return;+ running=true;+ updateDots(wordIdx);+ curWordKv.textContent=words[wordIdx];++ morphTimer=setTimeout(()=>{+ const next=(wordIdx+1)%words.length;+ morphTo(words[wordIdx],words[next],()=>{+ wordIdx=next;+ updateDots(wordIdx);curWordKv.textContent=words[wordIdx];+ morphTimer=setTimeout(cycle,100);+ });+ },getPause());+ }++ function start(){+ if(morphTimer)clearTimeout(morphTimer);running=false;wordIdx=0;+ const words=getWords();if(!words.length)return;+ buildDots(words);showWord(words[0]);curWordKv.textContent=words[0];+ setTimeout(cycle,100);+ }++ document.getElementById('restart-btn').addEventListener('click',start);+ document.getElementById('dur-sl').addEventListener('input',e=>{document.getElementById('dur-v').textContent=e.target.value+'ms'});+ document.getElementById('pause-sl').addEventListener('input',e=>{document.getElementById('pause-v').textContent=(e.target.value/1000).toFixed(1)+'s'});+ document.getElementById('stag-sl').addEventListener('input',e=>{document.getElementById('stag-v').textContent=e.target.value+'ms'});++ start();+</script>+</body>+</html>diff --git a/animations/05-text-typography/typewriter-effect/README.md b/animations/05-text-typography/typewriter-effect/README.mdnew file mode 100644index 00000000..170b2739--- /dev/null+++ b/animations/05-text-typography/typewriter-effect/README.md@@ -0,0 +1,86 @@+# 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.++## When to use it+- Hero headlines on developer tools, terminal-themed, or hacker-aesthetic sites+- Code samples that benefit from being "typed out" rather than appearing all at once+- Brief taglines and CTAs where the typing reveals the message progressively+- Chat interfaces, AI demos, and streaming text UI++## How it works+The core loop increments a counter and slices the full string to that length. A `<span>` cursor is appended after the text node:++```js+function type(text, speed = 50) {+ let i = 0;+ const el = document.querySelector('.output');+ const cursor = document.createElement('span');+ cursor.className = 'cursor';+ el.appendChild(cursor);++ function tick() {+ el.firstChild?.remove(); // remove old text node+ el.insertBefore(document.createTextNode(text.slice(0, i)), null); // prepend new+ el.appendChild(cursor); // cursor stays last+ if (++i <= text.length) setTimeout(tick, jitter(speed));+ }+ tick();+}++// Natural variance: ±20ms random offset+function jitter(base) {+ return base + Math.round((Math.random() - 0.5) * 40);+}+```++The cursor blinks via a CSS animation:++```css+.cursor {+ display: inline-block;+ width: 2px;+ height: 1.1em;+ background: var(--accent);+ animation: blink 1s step-end infinite;+}+@keyframes blink {+ 0%, 100% { opacity: 1; }+ 50% { opacity: 0; }+}+```++For the backspace-and-retype variant, decrement the substring index instead of incrementing, then redirect to a new target string:++```js+function deleteBack(from, to, callback) {+ let i = from.length;+ function del() {+ el.firstChild.textContent = from.slice(0, --i);+ if (i > 0) setTimeout(del, 30);+ else callback(to);+ }+ del();+}+```++## 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 |++## 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.+- **`aria-live="polite"`**: screen readers should not read each character as it types — add `aria-live="polite"` on the container so the screen reader waits for a pause before announcing, or use `aria-label` with the full final text.+- **Looping and rotation**: the "type, delete, retype" loop (cycling between multiple phrases) is the most common production pattern. Each phrase is typed, held briefly, then deleted before the next starts.+- **Performance**: `setTimeout` is accurate enough; `requestAnimationFrame` is overkill for typewriter timing and introduces unnecessary complexity.+- **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 timingdiff --git a/animations/05-text-typography/typewriter-effect/index.html b/animations/05-text-typography/typewriter-effect/index.htmlnew file mode 100644index 00000000..d7929c06--- /dev/null+++ b/animations/05-text-typography/typewriter-effect/index.html@@ -0,0 +1,180 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Typewriter Effect</title>+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--cursor-color:#58a6ff}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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)}+ .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}+ .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:monospace;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:monospace;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:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @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{height:auto;min-height:360px}}+ @media(prefers-reduced-motion:reduce){.cursor{animation:none!important;opacity:1!important}}+ </style>+</head>+<body>+<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>+ </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="#58a6ff" 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>+<script>+ const typeOut=document.getElementById('type-out');+ const statSpeed=document.getElementById('stat-speed');+ const statChars=document.getElementById('stat-chars');+ let timer=null,running=false;++ function makeCursor(){+ const c=document.createElement('span');+ c.className='cursor '+document.getElementById('cursor-sel').value;+ 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 type(text,done){+ if(timer)clearTimeout(timer);+ running=true;+ 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 deleteAndRetype(text){+ // Type full text, delete last word, retype it differently+ 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,()=>{+ 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)));+ j++;timer=setTimeout(retype,jitter(getSpeed()));+ }else{running=false;afterType();}+ }+ retype();+ }+ }+ setTimeout(del,500);+ });+ }++ function start(){+ const text=document.getElementById('text-inp').value;+ if(document.getElementById('delete-tog').checked){+ deleteAndRetype(text);+ }else{+ type(text,()=>afterType());+ }+ }++ function afterType(){+ if(document.getElementById('loop-tog').checked)setTimeout(start,1200);+ }++ document.getElementById('cursor-sel').addEventListener('change',()=>{if(!running)start()});+ document.getElementById('cursor-color').addEventListener('input',e=>{+ document.documentElement.style.setProperty('--cursor-color',e.target.value);+ });+ document.getElementById('spd-sl').addEventListener('input',e=>{+ document.getElementById('spd-v').textContent=e.target.value+'ms';+ });+ document.getElementById('replay-btn').addEventListener('click',()=>{+ if(timer)clearTimeout(timer);running=false;start();+ });++ start();+</script>+</body>+</html>diff --git a/animations/05-text-typography/variable-font-morph/README.md b/animations/05-text-typography/variable-font-morph/README.mdnew file mode 100644index 00000000..9eeab712--- /dev/null+++ b/animations/05-text-typography/variable-font-morph/README.md@@ -0,0 +1,77 @@+# Variable Font Morph++## What it is+Variable fonts pack an entire type family — thin through black, condensed through extended, roman through italic — into a single font file. CSS `font-variation-settings` exposes these axes as numeric values. Animating the values with CSS `transition` or `@keyframes` interpolates smoothly between any two points in the design space, enabling effects impossible with static fonts: weight pulsing, live slant, and fluid width changes.++## When to use it+- Hero headlines that breathe or pulse on a loop+- Hover effects where weight increases to signal interactivity+- Loading states where a spinner is replaced by weight-cycling text+- Brand expressions where the variable axis is part of the visual identity+- Interactive sliders that let users configure the weight/width/style live++## How it works+Set `font-variation-settings` on the element and apply a CSS transition. The browser interpolates all axes simultaneously:++```css+.headline {+ font-family: 'Recursive', sans-serif;+ font-variation-settings: 'wght' 400, 'CASL' 0, 'slnt' 0;+ transition: font-variation-settings 600ms cubic-bezier(.4, 0, .2, 1);+}++.headline:hover {+ font-variation-settings: 'wght' 800, 'CASL' 1, 'slnt' -15;+}+```++For JavaScript-driven morphing, update a CSS custom property:++```js+function apply(wght, casl, slnt) {+ const el = document.documentElement;+ el.style.setProperty('--wght', wght);+ el.style.setProperty('--CASL', casl); // 0–1 range for Recursive+ el.style.setProperty('--slnt', slnt); // –15 to 0 for Recursive+}+```++```css+.headline {+ font-variation-settings: 'wght' var(--wght), 'CASL' var(--CASL), 'slnt' var(--slnt);+}+```++For a looping morph between presets, use `setInterval`:++```js+const PRESETS = [+ { wght: 300, CASL: 0, slnt: 0 },+ { wght: 900, CASL: 0, slnt: 0 },+ { wght: 700, CASL: 1, slnt: -15 },+];+let i = 0;+setInterval(() => { apply(...Object.values(PRESETS[i++ % PRESETS.length])); }, 1400);+```++## Key parameters+| Axis | ID | Typical range | Effect |+|------|----|--------------|--------|+| Weight | `wght` | 100–900 (or 300–1000 for Recursive) | Thickness — most fonts have this axis |+| Slant | `slnt` | –15° to 0° | Oblique angle without a separate italic font |+| Casual | `CASL` | 0–1 (Recursive-specific) | Transitions between strict monospace and flowing casual style |+| Width | `wdth` | 75–125% | Horizontal compression/expansion (Fraunces, some others) |+| Optical size | `opsz` | 8–144pt | Stroke weight adjustments for different display sizes |++## Production notes+- **Axis ranges are font-specific**: `wght` 100–900 is standard, but Recursive goes to 1000, and some fonts start at 200. Always check the font's documentation or use a variable font inspector (e.g., Wakamai Fondue, wakamaifondue.com).+- **`font-variation-settings` is all-or-nothing**: if you set `font-variation-settings: 'wght' 700`, all other axes reset to their defaults. Always specify all axes you care about, even if unchanged.+- **CSS `font-weight` is preferred for weight**: `font-weight: 700` works with variable fonts and is more readable than `font-variation-settings: 'wght' 700`. Use `font-variation-settings` only for non-standard axes (`CASL`, `MONO`, etc.).+- **Transition performance**: variable font interpolation is handled by the GPU text rendering pipeline in modern browsers. It is not as fast as `transform`/`opacity` animations, but it is generally smooth on mid-range devices for single display elements.+- **Font loading**: this demo uses Google Fonts CDN (one external request). In production, self-host the variable font file and use `@font-face` with `font-display: swap` to avoid layout shift.+- **Recommended variable fonts**: Recursive (CASL, MONO, slnt, wght), Inter (wght), Fraunces (opsz, SOFT, WONK, wght), Bricolage Grotesque (opsz, wdth, wght).++## See also+- [Text Gradient Animation](../text-gradient-animation/) — another CSS-only text effect that animates a background property rather than the font itself+- [Kinetic Typography](../kinetic-typography/) — uses weight and scale changes as part of a narrative sequence+- [Outline to Fill](../outline-to-fill/) — another typographic state transition using CSS propertiesdiff --git a/animations/05-text-typography/variable-font-morph/index.html b/animations/05-text-typography/variable-font-morph/index.htmlnew file mode 100644index 00000000..d312ae61--- /dev/null+++ b/animations/05-text-typography/variable-font-morph/index.html@@ -0,0 +1,156 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Variable Font Morph</title>+ <link rel="preconnect" href="https://fonts.googleapis.com">+ <link href="https://fonts.googleapis.com/css2?family=Recursive:[email protected]&display=swap" rel="stylesheet">+ <style>+ :root{--bg:#060a10;--ui-bg:#0d1117;--ui-border:#21262d;--ui-accent:#58a6ff;--ui-text:#c9d1d9;--ui-muted:#8b949e;--stage-h:620px;--wght:400;--CASL:0;--slnt:0}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ body{background:var(--bg);color:var(--ui-text);font-family:monospace;padding:clamp(12px,3vw,24px)}+ header{margin-bottom:20px}+ header h1{font-size:clamp(11px,1.8vw,15px);letter-spacing:2px;text-transform:uppercase}+ 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:24px;padding:32px}+ .vf-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted)}+ .vf-text{+ font-family:'Recursive',Georgia,serif;+ font-size:clamp(56px,10vw,110px);+ line-height:1;+ color:#fff;+ letter-spacing:-0.02em;+ font-variation-settings:'wght' var(--wght),'CASL' var(--CASL),'slnt' var(--slnt);+ transition:font-variation-settings 600ms cubic-bezier(.4,0,.2,1);+ -webkit-user-select:none;user-select:none+ }+ .vf-sub{font-family:'Recursive',monospace;font-size:clamp(13px,2vw,18px);color:var(--ui-muted);letter-spacing:0.1em;font-variation-settings:'wght' 300,'CASL' 0,'slnt' 0}+ /* Axis readout */+ .axis-row{display:flex;gap:20px;font-size:10px;color:var(--ui-muted)}+ .axis-val{color:var(--ui-accent)}+ /* Preset buttons */+ .presets{display:flex;gap:6px;flex-wrap:wrap;justify-content:center}+ .preset-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:10px;padding:6px 12px;border-radius:4px;cursor:pointer;min-height:44px;min-width:70px;transition:border-color .15s,color .15s}+ @media(hover:hover){.preset-btn:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}+ /* 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)}+ .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:44px;text-align:right;color:var(--ui-text)}+ input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;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)}+ .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:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}+ @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}+ @media(prefers-reduced-motion:reduce){.vf-text{transition:none!important}}+ </style>+</head>+<body>+<header>+ <h1>Variable Font Morph</h1>+ <p>CSS font-variation-settings transitions between weight, slant, and casual axes of a variable font.</p>+</header>+<div class="layout">+ <div class="stage">+ <div class="vf-label">Variable</div>+ <div class="vf-text" id="vf-text">Type</div>+ <div class="vf-sub" id="vf-sub">Recursive · wght + CASL + slnt</div>+ <div class="axis-row">+ <span>wght: <span class="axis-val" id="wght-v">400</span></span>+ <span>casual: <span class="axis-val" id="casl-v">0.0</span></span>+ <span>slant: <span class="axis-val" id="slnt-v">0°</span></span>+ </div>+ <div class="presets">+ <button class="preset-btn" data-wght="300" data-casl="0" data-slnt="0">Thin</button>+ <button class="preset-btn" data-wght="400" data-casl="0" data-slnt="0">Regular</button>+ <button class="preset-btn" data-wght="700" data-casl="0" data-slnt="0">Bold</button>+ <button class="preset-btn" data-wght="900" data-casl="0" data-slnt="0">Black</button>+ <button class="preset-btn" data-wght="400" data-casl="1" data-slnt="-15">Casual Italic</button>+ <button class="preset-btn" data-wght="700" data-casl="1" data-slnt="0">Casual Bold</button>+ </div>+ </div>+ <aside>+ <p class="note">Variable fonts pack all weights into one file. font-variation-settings animates axes directly — CSS transitions work natively on any numeric axis.</p>+ <div class="lbl">Weight (wght)</div>+ <div class="sr"><input type="range" id="wght-sl" min="300" max="1000" value="400" step="10"><span class="sv" id="wght-sv">400</span></div>+ <div class="lbl">Casual (CASL)</div>+ <div class="sr"><input type="range" id="casl-sl" min="0" max="100" value="0" step="1"><span class="sv" id="casl-sv">0.0</span></div>+ <div class="lbl">Slant (slnt)</div>+ <div class="sr"><input type="range" id="slnt-sl" min="-15" max="0" value="0" step="1"><span class="sv" id="slnt-sv">0°</span></div>+ <div class="div"></div>+ <div class="lbl">Text</div>+ <input type="text" id="text-inp" value="Type">+ <button class="rst" id="auto-btn">▶ Auto-morph presets</button>+ <div class="kv"><span>Font</span><span class="v">Recursive</span></div>+ <div class="kv"><span>Axes</span><span class="v">wght · CASL · slnt</span></div>+ </aside>+</div>+<script>+const vfText=document.getElementById('vf-text');+const PRESETS=[+ {wght:300,CASL:0,slnt:0},{wght:900,CASL:0,slnt:0},{wght:700,CASL:1,slnt:-15},+ {wght:400,CASL:1,slnt:0},{wght:300,CASL:0,slnt:-15},{wght:1000,CASL:0,slnt:0}+];+let autoTimer=null,autoIdx=0;++function apply(wght,CASL,slnt){+ document.documentElement.style.setProperty('--wght',wght);+ document.documentElement.style.setProperty('--CASL',CASL/100);+ document.documentElement.style.setProperty('--slnt',slnt);+ document.getElementById('wght-v').textContent=wght;+ document.getElementById('casl-v').textContent=(CASL/100).toFixed(1);+ document.getElementById('slnt-v').textContent=slnt+'°';+ document.getElementById('wght-sl').value=wght;+ document.getElementById('casl-sl').value=CASL;+ document.getElementById('slnt-sl').value=slnt;+ document.getElementById('wght-sv').textContent=wght;+ document.getElementById('casl-sv').textContent=(CASL/100).toFixed(1);+ document.getElementById('slnt-sv').textContent=slnt+'°';+}++document.getElementById('wght-sl').addEventListener('input',e=>{+ const v=+e.target.value;+ document.getElementById('wght-sv').textContent=v;+ document.getElementById('wght-v').textContent=v;+ document.documentElement.style.setProperty('--wght',v);+});+document.getElementById('casl-sl').addEventListener('input',e=>{+ const v=e.target.value/100;+ document.getElementById('casl-sv').textContent=v.toFixed(1);+ document.getElementById('casl-v').textContent=v.toFixed(1);+ document.documentElement.style.setProperty('--CASL',v);+});+document.getElementById('slnt-sl').addEventListener('input',e=>{+ const v=+e.target.value;+ document.getElementById('slnt-sv').textContent=v+'°';+ document.getElementById('slnt-v').textContent=v+'°';+ document.documentElement.style.setProperty('--slnt',v);+});+document.getElementById('text-inp').addEventListener('input',e=>{+ vfText.textContent=e.target.value||'Type';+});+document.querySelectorAll('.preset-btn').forEach(btn=>{+ btn.addEventListener('click',()=>{+ clearInterval(autoTimer);autoTimer=null;+ apply(+btn.dataset.wght,+btn.dataset.casl*100,+btn.dataset.slnt);+ });+});+document.getElementById('auto-btn').addEventListener('click',()=>{+ if(autoTimer){clearInterval(autoTimer);autoTimer=null;document.getElementById('auto-btn').textContent='▶ Auto-morph presets';return;}+ document.getElementById('auto-btn').textContent='■ Stop';+ autoIdx=0;+ function step(){const p=PRESETS[autoIdx%PRESETS.length];apply(p.wght,p.CASL*100,p.slnt);autoIdx++;}+ step();autoTimer=setInterval(step,1400);+});+</script>+</body>+</html>diff --git a/index.html b/index.htmlindex d866d86e..efe0ebaf 100644--- a/index.html+++ b/index.html@@ -5,10 +5,9 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Animation Atlas</title><style>- :root{--bg:#060a10;--ui-bg:#0d1117;--border:#21262d;--text:#c9d1d9;--muted:#8b949e;--c1:#58a6ff;--c2:#56d364;--c3:#d2a8ff;--c4:#ffa657}+ :root{--bg:#060a10;--ui-bg:#0d1117;--border:#21262d;--text:#c9d1d9;--muted:#8b949e;--c1:#58a6ff;--c2:#56d364;--c3:#d2a8ff;--c4:#ffa657;--c5:#f85149}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}body{background:var(--bg);color:var(--text);font-family:monospace;padding:clamp(20px,4vw,56px) clamp(16px,4vw,48px);max-width:1100px;margin:0 auto}- /* Hero */.hero{margin-bottom:clamp(40px,6vw,72px);padding-bottom:32px;border-bottom:1px solid var(--border)}h1{font-size:clamp(14px,2.4vw,22px);letter-spacing:4px;text-transform:uppercase;margin-bottom:12px}.hero-sub{font-size:clamp(11px,1.4vw,13px);color:var(--muted);line-height:1.7;max-width:560px;margin-bottom:20px}@@ -16,13 +15,11 @@.hero-link{font-size:11px;color:var(--c1);text-decoration:none;letter-spacing:1px}@media(hover:hover){.hero-link:hover{text-decoration:underline}}.badge{font-size:10px;background:var(--ui-bg);border:1px solid var(--border);color:var(--muted);padding:4px 12px;border-radius:20px;letter-spacing:1px;white-space:nowrap}- /* Category */.cat{margin-bottom:clamp(40px,6vw,64px)}.cat-head{display:flex;align-items:center;gap:10px;margin-bottom:8px}.cat-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}h2{font-size:clamp(10px,1.4vw,12px);text-transform:uppercase;letter-spacing:2.5px;color:var(--muted)}.cat-desc{font-size:11px;color:var(--muted);margin-bottom:20px;padding-left:18px;line-height:1.6}- /* Card grid */.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}@media(max-width:960px){.grid{grid-template-columns:repeat(2,1fr)}}@media(max-width:600px){.grid{grid-template-columns:1fr}}@@ -31,12 +28,11 @@.card a{display:block;padding:14px 16px;text-decoration:none;color:inherit;height:100%}.card-name{font-size:clamp(11px,1.3vw,13px);font-weight:bold;margin-bottom:5px;transition:color .15s}.card-desc{font-size:10px;color:var(--muted);line-height:1.6}- /* Per-category accent on hover */.c1-cat .card:hover{border-color:var(--c1)}.c1-cat .card:hover .card-name{color:var(--c1)}.c2-cat .card:hover{border-color:var(--c2)}.c2-cat .card:hover .card-name{color:var(--c2)}.c3-cat .card:hover{border-color:var(--c3)}.c3-cat .card:hover .card-name{color:var(--c3)}.c4-cat .card:hover{border-color:var(--c4)}.c4-cat .card:hover .card-name{color:var(--c4)}- /* Coming soon */+ .c5-cat .card:hover{border-color:var(--c5)}.c5-cat .card:hover .card-name{color:var(--c5)}.planned{margin-bottom:16px}.planned h2{font-size:10px;text-transform:uppercase;letter-spacing:2.5px;color:var(--muted);margin-bottom:12px;opacity:.45}.soon-list{display:flex;gap:8px;flex-wrap:wrap}@@ -50,7 +46,7 @@<p class="hero-sub">A visual reference of web animation techniques. Each entry is a self-contained demo with an explanation of the mechanic — open any HTML file and it runs offline, no build step.</p><div class="hero-meta"><a class="hero-link" href="https://github.com/matinmonshizadeh/animation-handbook">github.com/matinmonshizadeh/animation-handbook →</a>- <span class="badge">61 animations · 4 categories</span>+ <span class="badge">72 animations · 5 categories</span></div></div><div id="root"></div>@@ -144,6 +140,24 @@ const CATS=[['accordion','Accordion Open/Close','Height animates between 0 and auto — JS measured height vs CSS grid-template-rows compared.'],['cursor-follower','Cursor Follower','Custom element follows mouse with lerp lag — mix-blend-mode: difference inverts any background.'],]+ },+ {+ name:'Text & Typography',cat:'c5-cat',dot:'#f85149',n:'05',+ desc:'Animations specifically for type — kinetic motion, character-level effects, gradient flows, and word transformations.',+ folder:'animations/05-text-typography',+ entries:[+ ['kinetic-typography','Kinetic Typography','Phrases enter, transform, and exit in a choreographed timeline — motion reinforces meaning.'],+ ['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.'],+ ['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.'],+ ['text-morphing','Text Morphing','One word transitions into another character by character — each letter slides out as the next slides in.'],+ ['text-gradient-animation','Text Gradient Animation','background-clip: text with animated background-position flows color through the characters.'],+ ['outline-to-fill','Outline to Fill','Hollow stroke letterforms fill with color — clip-path reveal or opacity crossfade.'],+ ['enter-exit-typography','Enter/Exit Typography','Three-act phrase lifecycle: enter → hold → exit, sequenced for storytelling.'],+ ['rotate-word-carousel','Rotate Word Carousel','One keyword cycles through a list while the surrounding sentence stays static.'],+ ]}];@@ -159,7 +173,7 @@ CATS.forEach(cat=>{});const planned=document.createElement('div');planned.className='planned';-planned.innerHTML=`<h2>Coming soon</h2><div class="soon-list"><span class="soon">05 — Text & Typography</span><span class="soon">06 — 3D & Advanced</span><span class="soon">07 — Ambient & Background</span></div>`;+planned.innerHTML=`<h2>Coming soon</h2><div class="soon-list"><span class="soon">06 — 3D & Advanced</span><span class="soon">07 — Ambient & Background</span></div>`;root.appendChild(planned);</script></body>