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 Loading Spinner to the guided-steps page
matin72c8e3ddb6f8
diff --git a/animations/04-micro-interactions/loading-spinner/README.md b/animations/04-micro-interactions/loading-spinner/README.mdindex 0dac6d3d..2d4422a4 100644--- a/animations/04-micro-interactions/loading-spinner/README.md+++ b/animations/04-micro-interactions/loading-spinner/README.md@@ -1,7 +1,7 @@# Loading Spinner## What it is-A loading spinner is a looping animation indicating that the system is busy and the user should wait. Unlike a progress bar, it conveys no information about duration — only that work is happening. This makes it appropriate for unpredictably-timed operations like network requests, file processing, or authentication handshakes.+A loading spinner is a small shape that keeps moving in a loop to show that the system is busy. It says nothing about how long the wait will be, only that work is going on, so it suits waits of unknown length, such as a network request. The demo shows six common designs.## When to use it- Network requests where response time is unknown@@ -60,20 +60,19 @@ The bounce-dots variant uses staggered animation delays on three sibling element## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Speed | 800ms | 600–1000ms is the legible range; faster reads as anxious |-| Size | 40px | 20px inline, 40px full-screen, 60–80px for empty states |-| Color | accent | Should be distinct from the page background |-| Minimum display | 400ms | Flash a spinner for less than 400ms and hide it — the flash is worse than nothing |+| Speed | Normal | How long one turn takes: slow is 1.3s, normal 0.8s and fast 0.5s; 0.6 to 1 second reads as calm, faster as anxious |+| Size | Medium | Small is 28px, medium 40px and large 52px; small fits inside a button, large fills an empty area |+| Color | Blue | The spinner's color; pick one that stands out from the page |## Production notes- **Minimum display time**: if the operation completes in under ~400ms, either show no spinner at all or enforce a minimum display time. A spinner that flashes briefly causes more confusion than it resolves.- **Inline button spinner**: replace the button label with a spinner on click, re-enable on response. This pattern prevents double-submission.- **`role="status"` and `aria-label`**: screen readers need to announce the loading state. Add `role="status"` and `aria-label="Loading"` to the spinner container.-- **`prefers-reduced-motion`**: reduce to a simple opacity pulse or hide the spinner and rely on `aria-live` region announcements.+- **`prefers-reduced-motion`**: under reduced motion the demo starts paused, so the spinners stay still until the visitor presses Play. In production, reduce the spinner to a simple opacity pulse, or hide it and rely on an `aria-live` announcement.- **React ecosystem**: `react-spinners` (by David Hu) has 15+ variants. For Tailwind, use the `animate-spin` utility on a bordered circle div.- **When not to use**: if you know total progress (file upload, multi-step process), use a progress bar instead — it conveys more information and reduces anxiety.## See also-- [Progress Animation](../progress-animation/) — for known-duration or known-percentage loads-- [Skeleton Loader](../skeleton-loader/) — for content-shaped placeholders-- [Checkmark Draw](../checkmark-draw/) — the success state after a spinner resolves+- [Progress Animation](../progress-animation/) — a bar that shows how much is done+- [Skeleton Loader](../skeleton-loader/) — gray shapes stand in for the content+- [Checkmark Draw](../checkmark-draw/) — the success sign once the wait is overdiff --git a/animations/04-micro-interactions/loading-spinner/index.html b/animations/04-micro-interactions/loading-spinner/index.htmlindex ff4fba80..6a78ae28 100644--- a/animations/04-micro-interactions/loading-spinner/index.html+++ b/animations/04-micro-interactions/loading-spinner/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Loading Spinner — Animation Handbook</title>- <meta name="description" content="Six spinner variants from a single CSS color and speed — ring, dots, arc, bounce, pulse, square.">+ <meta name="description" content="Six small shapes loop to show that something is loading. Best for short waits."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/loading-spinner/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,30 +12,21 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Loading Spinner — Animation Handbook">- <meta property="og:description" content="Six spinner variants from a single CSS color and speed — ring, dots, arc, bounce, pulse, square.">+ <meta property="og:description" content="Six small shapes loop to show that something is loading. Best for short waits."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/loading-spinner/"><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="Loading Spinner — Animation Handbook">- <meta name="twitter:description" content="Six spinner variants from a single CSS color and speed — ring, dots, arc, bounce, pulse, square.">+ <meta name="twitter:description" content="Six small shapes loop to show that something is loading. Best for short waits."><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": "Loading Spinner", "name": "Loading Spinner", "description": "Six spinner variants from a single CSS color and speed — ring, dots, arc, bounce, pulse, square.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/loading-spinner/", "inLanguage": "en", "articleSection": "Micro-Interactions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Micro-Interactions, Loading Spinner"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Loading Spinner", "name": "Loading Spinner", "description": "Six small shapes loop to show that something is loading. Best for short waits.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/loading-spinner/", "inLanguage": "en", "articleSection": "Micro-Interactions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Micro-Interactions, Loading Spinner"}</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:#ff9d5c;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--spd:800ms;--clr:#58a6ff;--sz:40px}+ :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-muted:#8a8a92;--spd:800ms;--clr:#58a6ff;--sz:40px}*,*::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(11px,1.8vw,15px);letter-spacing:-.01em}- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:center;justify-content:center;padding:32px}- .grid{display:grid;grid-template-columns:repeat(3,1fr);gap:20px;width:100%;max-width:380px}- .spin-cell{display:flex;flex-direction:column;align-items:center;gap:10px;padding:16px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px}- .spin-label{font-size:9px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted);text-align:center}+ .stage{display:flex;align-items:center;justify-content:center;padding:16px;background:#0b0b0d}+ .grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;width:100%;max-width:380px}+ .spin-cell{display:flex;flex-direction:column;align-items:center;gap:10px;padding:12px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px}+ .spin-label{font-size:11px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted);text-align:center}/* 1. Ring */.sp-ring{width:var(--sz);height:var(--sz);border-radius:50%;border:3px solid rgba(255,255,255,.1);border-top-color:var(--clr);animation:spin var(--spd) linear infinite}@keyframes spin{to{transform:rotate(360deg)}}@@ -64,100 +55,175 @@/* 6. Square rotate */.sp-square{width:calc(var(--sz)*0.65);height:calc(var(--sz)*0.65);border:3px solid var(--clr);animation:sq-spin var(--spd) ease-in-out infinite}@keyframes sq-spin{0%{transform:rotate(0deg)}50%{transform:rotate(180deg) scale(.7)}100%{transform:rotate(360deg)}}- /* 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)}- input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:420px}.grid{grid-template-columns:repeat(2,1fr)}}- @media(prefers-reduced-motion:reduce){[class^=sp-],[class^=sp-] *{animation-play-state:paused!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="../shimmer-effect/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../progress-animation/" 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/04-micro-interactions/loading-spinner/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Loading Spinner</h1>- <p>Six spinner variants from a single CSS color and speed — ring, dots, arc, bounce, pulse, square.</p>-</header>-<div class="layout">- <div class="stage">- <div class="grid">- <div class="spin-cell">- <div class="sp-ring" role="status" aria-label="Loading"></div>- <div class="spin-label">Ring</div>+<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="../shimmer-effect/" rel="prev" aria-label="Previous: Shimmer Effect"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Shimmer Effect</span></a><a href="../progress-animation/" rel="next" aria-label="Next: Progress Animation"><span><span class="hb-dir">Next: </span>Progress Animation</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">04.11 · Micro-Interactions</p>+ <h1>Loading Spinner</h1>+ <p class="hb-lede">Six small shapes loop to show that something is loading. Best for short waits.</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">+ <div class="grid">+ <div class="spin-cell">+ <div class="sp-ring" role="status" aria-label="Loading"></div>+ <div class="spin-label">Ring</div>+ </div>+ <div class="spin-cell">+ <div class="sp-dots" role="status" aria-label="Loading">+ <span></span><span></span><span></span><span></span><span></span><span></span>+ </div>+ <div class="spin-label">Orbit</div>+ </div>+ <div class="spin-cell">+ <svg class="sp-arc" viewBox="0 0 40 40" role="status" aria-label="Loading">+ <circle cx="20" cy="20" r="16"/>+ </svg>+ <div class="spin-label">Arc</div>+ </div>+ <div class="spin-cell">+ <div class="sp-bounce" role="status" aria-label="Loading">+ <span></span><span></span><span></span>+ </div>+ <div class="spin-label">Bounce</div>+ </div>+ <div class="spin-cell">+ <div class="sp-pulse" role="status" aria-label="Loading"></div>+ <div class="spin-label">Pulse</div>+ </div>+ <div class="spin-cell">+ <div class="sp-square" role="status" aria-label="Loading"></div>+ <div class="spin-label">Square</div>+ </div></div>- <div class="spin-cell">- <div class="sp-dots" role="status" aria-label="Loading">- <span></span><span></span><span></span><span></span><span></span><span></span>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause="css" 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="css" 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="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="speed-lbl">Speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-ms="1300" aria-pressed="false">Slow</button>+ <button type="button" data-ms="800" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="500" aria-pressed="false">Fast</button></div>- <div class="spin-label">Orbit</div>+ <p class="hb-hint">Fast spinning can feel anxious.</p></div>- <div class="spin-cell">- <svg class="sp-arc" viewBox="0 0 40 40" role="status" aria-label="Loading">- <circle cx="20" cy="20" r="16"/>- </svg>- <div class="spin-label">Arc</div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="size-lbl">Size</p>+ <div class="seg" id="size-seg" role="group" aria-labelledby="size-lbl">+ <button type="button" data-px="28" aria-pressed="false">Small</button>+ <button type="button" data-px="40" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-px="52" aria-pressed="false">Large</button>+ </div>+ <p class="hb-hint">Small fits inside a button; large fills an empty area.</p></div>- <div class="spin-cell">- <div class="sp-bounce" role="status" aria-label="Loading">- <span></span><span></span><span></span>+ </div>+ <details class="hb-options">+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="color-lbl">Color</p>+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">+ <button type="button" aria-pressed="false" aria-label="Pink" data-c="#ff6f8b" style="background:#ff6f8b"></button>+ <button type="button" aria-pressed="false" aria-label="White" data-c="#f4f4f2" style="background:#f4f4f2"></button>+ <button type="button" class="on" aria-pressed="true" aria-label="Blue" data-c="#58a6ff" style="background:#58a6ff"></button>+ <button type="button" aria-pressed="false" aria-label="Purple" data-c="#d2a8ff" style="background:#d2a8ff"></button>+ <button type="button" aria-pressed="false" aria-label="Green" data-c="#56d364" style="background:#56d364"></button>+ <button type="button" aria-pressed="false" aria-label="Orange" data-c="#ffa657" style="background:#ffa657"></button>+ </div>+ <p class="hb-hint">Pick a color that stands out from the page.</p></div>- <div class="spin-label">Bounce</div></div>- <div class="spin-cell">- <div class="sp-pulse" role="status" aria-label="Loading"></div>- <div class="spin-label">Pulse</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 loading spinner to [the place where people wait for something to load]. Use a small shape that keeps moving in a steady loop, such as a ring with one colored part turning around, dots circling or dots bouncing in turn, to show that work is going on when you cannot say how long it will take. Show it only for waits longer than about half a second, and tell screen readers that something is loading. If you know how far along the task is, use a progress bar instead. If the visitor has reduced motion turned on, fade it gently instead of spinning. 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="spin-cell">- <div class="sp-square" role="status" aria-label="Loading"></div>- <div class="spin-label">Square</div>+ <div class="hb-copy-row">+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p></div></div>- </div>- <aside>- <p class="note">Use spinners for unknown-duration loads only. For known-duration loads, a progress bar is less anxious — it shows how much longer.</p>- <div class="lbl">Speed</div>- <div class="sr"><input type="range" id="spd-sl" min="400" max="2000" value="800" step="50"><span class="sv" id="spd-v">800ms</span></div>- <div class="lbl">Size</div>- <div class="sr"><input type="range" id="sz-sl" min="20" max="70" value="40" step="2"><span class="sv" id="sz-v">40px</span></div>- <div class="lbl">Color</div>- <input type="color" id="clr-pick" value="#58a6ff" aria-label="Spinner color">- <div class="div"></div>- <p class="note" style="opacity:.7">Minimum display time: show a spinner for at least 400ms — flashing it for 50ms is worse than showing nothing.</p>- </aside>-</div>+ </section>++ <section class="hb-about" aria-labelledby="hb-what-title">+ <div class="hb-what">+ <h2 id="hb-what-title">What it is</h2>+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>+ </div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Network waits</li><li>Buttons while sending</li><li>Short waits</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Known-length tasks</li><li>Very quick loads</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>- document.getElementById('spd-sl').addEventListener('input',e=>{- document.getElementById('spd-v').textContent=e.target.value+'ms';- document.documentElement.style.setProperty('--spd',e.target.value+'ms');- });- document.getElementById('sz-sl').addEventListener('input',e=>{- document.getElementById('sz-v').textContent=e.target.value+'px';- document.documentElement.style.setProperty('--sz',e.target.value+'px');+ const stage=document.querySelector('.stage');+ const vars=document.documentElement.style;+ const pulse=document.querySelector('.sp-pulse');+ let turnMs=800;++ 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);+ }));+ }+ // A new --spd keeps the time already played, so every spinner would jump to another point of its turn.+ // Scaling each animation's time by the same factor as its length keeps them where they are, moving or paused.+ choices('speed-seg',d=>{+ const next=+d.ms;+ stage.getAnimations({subtree:true}).forEach(a=>{if(a.currentTime!=null)a.currentTime=a.currentTime*next/turnMs});+ turnMs=next;+ vars.setProperty('--spd',next+'ms');});- document.getElementById('clr-pick').addEventListener('input',e=>{- document.documentElement.style.setProperty('--clr',e.target.value);- document.querySelector('.sp-pulse').style.borderColor=e.target.value;- document.querySelector('.sp-pulse').style.background=e.target.value+'26';+ choices('size-seg',d=>{vars.setProperty('--sz',d.px+'px')});+ // The Pulse spinner also fills its ring with the color at 15% opacity (26 is 15% written in hex)+ choices('color-sw',d=>{+ vars.setProperty('--clr',d.c);+ pulse.style.background=d.c+'26';});</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 bdc29776..0d75e15d 100644--- a/index.html+++ b/index.html@@ -961,7 +961,7 @@ const CATS=[['success-confetti','Success Confetti','Completing an action fires a canvas confetti burst — rotating rectangles with gravity and spin.'],['skeleton-loader','Skeleton Loader','Gray shapes hold the place of content while it loads. Best for feeds and cards.'],['shimmer-effect','Shimmer Effect','A band of light sweeps over gray placeholders. Best for loading screens.'],- ['loading-spinner','Loading Spinner','Six spinner variants from a single CSS color and speed — ring, orbit, arc, bounce, pulse, square.'],+ ['loading-spinner','Loading Spinner','Six small shapes loop to show that something is loading. Best for short waits.'],['progress-animation','Progress Animation','A bar, a ring and steps fill up to show progress. Best for uploads.'],['checkmark-draw','Checkmark Draw','SVG path draws progressively on success — stroke-dashoffset animates from full length to zero.'],['form-field-morph','Form Field Morph','Floating label rises out of the input on focus — persists when the field is filled.'],