176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: move Variable Font Morph to the guided-steps page
matin5276e0e68b5a
diff --git a/animations/05-text-typography/variable-font-morph/README.md b/animations/05-text-typography/variable-font-morph/README.mdindex 3f56a284..48e2b5c9 100644--- a/animations/05-text-typography/variable-font-morph/README.md+++ b/animations/05-text-typography/variable-font-morph/README.md@@ -1,7 +1,7 @@# 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.+A variable font holds a whole range of styles, such as thin to black, in one file, and each style is just a number. Because of that, the browser can move smoothly from one style to another, so a word can grow heavier or lighter as you watch. In the demo, the word moves between the site font's regular and black weights and leans over by being tilted, since this font has no slanted style of its own.## When to use it- Hero headlines that breathe or pulse on a loop@@ -15,30 +15,33 @@ Set `font-variation-settings` on the element and apply a CSS transition. The bro```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);+ font-weight: 400;+ font-variation-settings: 'wght' 400;+ transition: font-weight 600ms cubic-bezier(.4, 0, .2, 1),+ font-variation-settings 600ms cubic-bezier(.4, 0, .2, 1);}.headline:hover {- font-variation-settings: 'wght' 800, 'CASL' 1, 'slnt' -15;+ font-weight: 800;+ font-variation-settings: 'wght' 800;}```For JavaScript-driven morphing, update a CSS custom property:```js-function apply(wght, casl, slnt) {+function apply(wght, 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+ el.style.setProperty('--wght', wght); // 400–900 for the site font+ el.style.setProperty('--slnt', slnt); // 0 to –15, drawn as a tilt}``````css.headline {- font-variation-settings: 'wght' var(--wght), 'CASL' var(--CASL), 'slnt' var(--slnt);+ font-weight: var(--wght);+ font-variation-settings: 'wght' var(--wght);+ transform: skewX(calc(var(--slnt) * 1deg)); /* the site font has no slant axis */}```@@ -46,32 +49,30 @@ For a looping morph between presets, use `setInterval`:```jsconst PRESETS = [- { wght: 300, CASL: 0, slnt: 0 },- { wght: 900, CASL: 0, slnt: 0 },- { wght: 700, CASL: 1, slnt: -15 },+ { wght: 400, slnt: 0 },+ { wght: 900, slnt: 0 },+ { wght: 700, slnt: -15 },];let i = 0;-setInterval(() => { apply(...Object.values(PRESETS[i++ % PRESETS.length])); }, 1400);+setInterval(() => { apply(...Object.values(PRESETS[i++ % PRESETS.length])); }, 1400); // Speed + an 800ms rest```## 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 |+| Parameter | Default | Effect |+|-----------|---------|--------|+| Speed | Normal | How long each change takes: slow is 1000ms, normal 600ms and fast 350ms; the word then rests for 800ms before the next |+| Leans as it changes | on | Some changes also tilt the word by up to 15 degrees; off, only the weight changes |+| Your text | Type | The word that changes |## 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 ships no font files — it targets `system-ui`, which resolves to a real variable font on modern OSes (Segoe UI Variable on Windows 11, San Francisco on macOS), so the `wght` axis morphs smoothly offline. `font-weight` and a `skewX()` transform are wired as universal fallbacks so weight and slant still animate where no variable font is present. In production, self-host a variable font (e.g. Recursive) via `@font-face` with `font-display: swap` to unlock font-specific axes like `CASL`.+- **Font loading**: the demo uses the site's own font, Schibsted Grotesk, which every page already loads and which is variable in weight from 400 to 900, so the weight morphs smoothly offline. It has no slant axis, so the lean is a `skewX()` tilt. A font with more axes gives you more to morph: Recursive, for example, adds Casual and slant axes. Self-host it with `@font-face` and `font-display: swap`.- **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 properties+- [Text Gradient Animation](../text-gradient-animation/) — colors flow through the letters instead+- [Kinetic Typography](../kinetic-typography/) — words that each move in their own way+- [Outline to Fill](../outline-to-fill/) — hollow letters fill with colordiff --git a/animations/05-text-typography/variable-font-morph/index.html b/animations/05-text-typography/variable-font-morph/index.htmlindex 6536386b..58cc7b70 100644--- a/animations/05-text-typography/variable-font-morph/index.html+++ b/animations/05-text-typography/variable-font-morph/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Variable Font Morph — Animation Handbook</title>- <meta name="description" content="CSS font-variation-settings transitions between weight, slant, and casual axes of a variable font.">+ <meta name="description" content="A word smoothly turns bold, then light, and leans over. Best for headlines."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/variable-font-morph/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,188 +12,189 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Variable Font Morph — Animation Handbook">- <meta property="og:description" content="CSS font-variation-settings transitions between weight, slant, and casual axes of a variable font.">+ <meta property="og:description" content="A word smoothly turns bold, then light, and leans over. Best for headlines."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/variable-font-morph/"><meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:title" content="Variable Font Morph — Animation Handbook">- <meta name="twitter:description" content="CSS font-variation-settings transitions between weight, slant, and casual axes of a variable font.">+ <meta name="twitter:description" content="A word smoothly turns bold, then light, and leans over. Best for headlines."><meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">- <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Variable Font Morph", "name": "Variable Font Morph", "description": "CSS font-variation-settings transitions between weight, slant, and casual axes of a variable font.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/variable-font-morph/", "inLanguage": "en", "articleSection": "Text & Typography", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Text & Typography, Variable Font Morph"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Variable Font Morph", "name": "Variable Font Morph", "description": "A word smoothly turns bold, then light, and leans over. Best for headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/variable-font-morph/", "inLanguage": "en", "articleSection": "Text & Typography", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Text & Typography, Variable Font Morph"}</script><style>- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff6f8b;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--wght:400;--CASL:0;--slnt:0}+ :root{--ui-accent:#ff6f8b;--wght:400;--slnt:0;--morph-dur:600ms}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}- header{margin-bottom:20px}- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(16px,2.2vw,22px);letter-spacing:-.01em}- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}- .stage{flex:1;min-width:0;min-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)}+ .stage{display:flex;align-items:center;justify-content:center;background:#04060c;padding:clamp(20px,4vw,48px)}.vf-text{- font-family:'Recursive','Segoe UI Variable',system-ui,'Segoe UI',sans-serif;- font-size:clamp(56px,10vw,110px);- line-height:1;+ width:100%;max-width:720px;+ font-size:clamp(44px,9vw,100px);+ line-height:1.15;color:#fff;- letter-spacing:-0.02em;- max-width:100%;overflow-wrap:anywhere;text-align:center;- /* wght/slnt are standard axes system-ui exposes; font-weight + skewX are the- universal fallback so the morph is visible even without a variable font. */+ text-align:center;+ overflow-wrap:anywhere;font-weight:var(--wght);- font-variation-settings:'wght' var(--wght),'CASL' var(--CASL),'slnt' var(--slnt);- /* slnt is negative for a right-leaning (italic) slant, and so is skewX. */+ font-variation-settings:'wght' var(--wght);+ /* the site font has no slant axis, so slnt is drawn as a skewX tilt */transform:skewX(calc(var(--slnt) * 1deg));- transition:font-variation-settings 600ms cubic-bezier(.4,0,.2,1),font-weight 600ms cubic-bezier(.4,0,.2,1),transform 600ms cubic-bezier(.4,0,.2,1);+ transition:font-variation-settings var(--morph-dur) cubic-bezier(.4,0,.2,1),+ font-weight var(--morph-dur) cubic-bezier(.4,0,.2,1),+ transform var(--morph-dur) cubic-bezier(.4,0,.2,1);-webkit-user-select:none;user-select:none}- .vf-sub{font-family:'Recursive','Segoe UI Variable',system-ui,monospace;font-size:clamp(13px,2vw,18px);color:var(--ui-muted);letter-spacing:0.1em;font-weight:300}- /* 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:var(--mono);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:var(--mono);font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}- input[type=text]:focus{border-color:var(--ui-accent)}- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}- @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>-<style id="ah-inject">-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}-body{padding-top:46px}-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}-.ah-home{color:var(--ah-ink);font-weight:600}-.ah-actions{display:flex;align-items:center;gap:2px}-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}-.ah-copied{color:var(--ah-accent)!important}-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}-@media print{.ah-bar{display:none}body{padding-top:0}}-</style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">+ <script src="../../../assets/js/demo-page.js?v=3" defer></script></head>-<body>-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../scramble-text/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../text-clip-path-reveal/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/05-text-typography/variable-font-morph/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<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">system-ui · wght + slnt (CASL needs a font that exposes it)</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>+<body class="hb" data-hb-kind="loop">+<nav class="hb-bar" aria-label="Animation Handbook">+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>+ <span class="hb-pager"><a href="../scramble-text/" rel="prev" aria-label="Previous: Scramble / Glitch Text"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Scramble / Glitch Text</span></a><a href="../text-clip-path-reveal/" rel="next" aria-label="Next: Text Clip-Path Reveal"><span><span class="hb-dir">Next: </span>Text Clip-Path Reveal</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">05.04 · Text & Typography</p>+ <h1>Variable Font Morph</h1>+ <p class="hb-lede">A word smoothly turns bold, then light, and leans over. Best for headlines.</p>+ </header>++ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">1</span>+ <div><h2 id="hb-watch-title">Watch it</h2><p>It moves by itself. Pause it to look closely, or turn on slow motion to see each part of the movement.</p></div>+ </div>+ <div class="stage hb-dots hb-grow" id="stage">+ <div class="vf-text" id="vf-text">Type</div>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>+ </div>+ </section>++ <section class="hb-step hb-try" aria-labelledby="hb-try-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">2</span>+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and see the difference as it moves.</p></div></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 class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="speed-lbl">Speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-dur="1000" aria-pressed="false">Slow</button>+ <button type="button" data-dur="600" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-dur="350" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How long each change of style takes.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Leans as it changes</span><input class="hb-switch" type="checkbox" role="switch" id="lean-tog" checked autocomplete="off"></label>+ <p class="hb-hint">Adds a slant to some of the changes.</p>+ </div></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">system-ui</span></div>- <div class="kv"><span>Axes</span><span class="v">wght · CASL · slnt</span></div>- </aside>-</div>+ <details class="hb-options">+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>+ <div class="hb-settings">+ <div class="hb-setting">+ <label class="hb-setting-name" for="text-inp">Your text</label>+ <input class="hb-text" type="text" id="text-inp" value="Type" autocomplete="off">+ <p class="hb-hint">Short words show the change best.</p>+ </div>+ </div>+ </details>+ </section>++ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">3</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>+ </div>+ <div class="hb-card">+ <p class="hb-prompt">Add a variable font morph to [your headline or word]. Use a variable font, which holds a whole range of weights in one file, and change the weight smoothly so the letters grow heavier and lighter as you watch, moving through a few styles in turn and resting briefly on each. When the settings include it, the word also leans over during some changes: a font with its own slant does this best, and a slight tilt works for fonts without one. Change the weight through the font itself, not by scaling, so the text stays sharp. If the visitor has reduced motion turned on, keep the word in one style. Match the settings listed below.</p>+ <div class="hb-chips-box" hidden>+ <p class="hb-chips-title">Your settings</p>+ <ul class="hb-chips"></ul>+ </div>+ <div class="hb-copy-row">+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>+ </div>+ </div>+ </section>++ <section class="hb-about" aria-labelledby="hb-what-title">+ <div class="hb-what">+ <h2 id="hb-what-title">What it is</h2>+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>+ </div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Headlines</li><li>Logos</li><li>Loading text</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Body text</li><li>Small text</li></ul>+ </div>+ </section>++ <section class="hb-related" aria-labelledby="hb-related-title" hidden>+ <h2 id="hb-related-title">Similar animations</h2>+ <div class="hb-rel-list"></div>+ </section>+</main>+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer><script>-const 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 stopAuto(){clearInterval(autoTimer);autoTimer=null;document.getElementById('auto-btn').textContent='▶ Auto-morph presets';}+ const vfText=document.getElementById('vf-text');+ const stage=document.getElementById('stage');+ const vars=document.documentElement.style;+ const slowTog=document.getElementById('slow-tog');+ const leanTog=document.getElementById('lean-tog');+ const txtIn=document.getElementById('text-inp');+ const PRESETS=[+ {wght:400,slnt:0},{wght:900,slnt:0},{wght:700,slnt:-15},+ {wght:500,slnt:0},{wght:400,slnt:-15},{wght:900,slnt:0}+ ];+ let morph=600,idx=0,current=PRESETS[0];++ function curDur(){return slowTog.checked?morph*3:morph}-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+'°';-}+ // Pause freezes the step under way: its transitions stop where they are and its timer keeps the time it+ // had left. Every timer of the loop goes through wait(), so there is always exactly one chain and Play can+ // never start a second one.+ let timer=0,next=null,due=0,left=0,held=[],paused=false;+ function wait(fn,ms){clearTimeout(timer);next=fn;if(paused){left=ms;return}due=performance.now()+ms;timer=setTimeout(()=>{next=null;fn()},ms)}+ function freeze(){paused=true;clearTimeout(timer);if(next)left=Math.max(0,due-performance.now());held=stage.getAnimations({subtree:true}).filter(a=>a.playState==='running');held.forEach(a=>a.pause())}+ function thaw(){paused=false;held.forEach(a=>{if(a.playState==='paused')a.play()});held=[];if(next)wait(next,left)}+ document.addEventListener('hb:pause',e=>e.detail.paused?freeze():thaw());-document.getElementById('wght-sl').addEventListener('input',e=>{- stopAuto();- 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=>{- stopAuto();- 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=>{- stopAuto();- 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',()=>{- stopAuto();- apply(+btn.dataset.wght,+btn.dataset.casl*100,+btn.dataset.slnt);+ // Applies the next preset, then schedules the step after it. --morph-dur is set fresh on every call, so a+ // Slow motion change takes effect on this step's own transition (and the wait that matches it), never on+ // one already drawn.+ function step(){+ const d=curDur();+ vars.setProperty('--morph-dur',d+'ms');+ current=PRESETS[idx%PRESETS.length];+ idx++;+ vars.setProperty('--wght',current.wght);+ vars.setProperty('--slnt',leanTog.checked?current.slnt:0);+ wait(step,d+800);+ }++ // Applied to the word on screen at once, so the change shows even while paused.+ leanTog.addEventListener('change',()=>{+ vars.setProperty('--slnt',leanTog.checked?current.slnt:0);+ });+ txtIn.addEventListener('input',()=>{+ vfText.textContent=txtIn.value||'Type';});-});-document.getElementById('auto-btn').addEventListener('click',()=>{- if(autoTimer){stopAuto();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);-});++ function choices(id,pick){+ const buttons=document.querySelectorAll('#'+id+' button');+ buttons.forEach(b=>b.addEventListener('click',()=>{+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});+ pick(b.dataset);+ }));+ }+ choices('speed-seg',d=>{morph=+d.dur});++ step();</script>-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script></body></html>diff --git a/index.html b/index.htmlindex 692493bb..9fb58c7f 100644--- a/index.html+++ b/index.html@@ -990,7 +990,7 @@ const CATS=[['kinetic-typography','Kinetic Typography','Words arrive and leave one by one, each moving its own way. Best for intros.'],['typewriter-effect','Typewriter Effect','Text types itself out behind a blinking cursor. Best for short taglines.'],['scramble-text','Scramble / Glitch Text','Random symbols lock into the real text, left to right. Best for tech headlines.'],- ['variable-font-morph','Variable Font Morph','CSS font-variation-settings animates weight, slant, and casual axes of a variable font.'],+ ['variable-font-morph','Variable Font Morph','A word smoothly turns bold, then light, and leans over. Best for headlines.'],['text-clip-path-reveal','Text Clip-Path Reveal','Each line of a headline is uncovered in turn. Best for big headlines.'],['marquee-ticker','Marquee / Ticker','Text scrolls sideways in an endless loop, with no seam. Best for news tickers.'],['text-morphing','Text Morphing','One word changes into the next, letter by letter. Best for short labels.'],