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 Progress Animation to the guided-steps page
matin961633be5f94
diff --git a/animations/04-micro-interactions/progress-animation/README.md b/animations/04-micro-interactions/progress-animation/README.mdindex 4bbf743b..838630a4 100644--- a/animations/04-micro-interactions/progress-animation/README.md+++ b/animations/04-micro-interactions/progress-animation/README.md@@ -1,7 +1,7 @@# Progress Animation## What it is-A progress animation visualizes completion percentage through a filling shape — a horizontal bar, a circular ring, or a stepped sequence. It differs from a spinner in that it conveys specific information: how much is done and how much remains. This reduces user anxiety during long operations and sets accurate expectations about wait time.+A progress animation shows how much of a task is done by filling a shape: a bar, a ring or a row of steps. Unlike a spinner, it tells people how much is left, which makes a long wait easier. In the demo, all three are driven by the same percentage.## When to use it- File uploads and downloads where byte progress is available@@ -11,14 +11,17 @@ A progress animation visualizes completion percentage through a filling shape- Any operation where `loaded / total` can be computed## How it works-**Linear bar**: update `width` via a CSS transition, or animate it manually with `requestAnimationFrame` for easing control:+**Linear bar**: keep the fill as wide as the track and slide it in from the left with `transform: translateX()`; the track's `overflow: hidden` hides the part still outside, and a transform never makes the page lay out again. Move it with a CSS transition, or with `requestAnimationFrame` for easing control:```css+.prog-track { overflow: hidden; border-radius: 4px; }+.prog-fill {height: 100%;+ width: 100%;background: #58a6ff;- width: 0%;- transition: width 2000ms ease-out;+ transform: translateX(-100%); /* empty: the whole fill sits left of the track */+ transition: transform 2000ms ease-out;}```@@ -29,7 +32,7 @@ function animateProgress(target, duration) {function tick(now) {const t = Math.min((now - start) / duration, 1);const eased = 1 - (1 - t) ** 3; // ease-out cubic- fill.style.width = (target * eased) + '%';+ fill.style.transform = 'translateX(' + (target * eased - 100) + '%)';if (t < 1) requestAnimationFrame(tick);}requestAnimationFrame(tick);@@ -68,20 +71,21 @@ circle.style.strokeDashoffset = 201 * (1 - p);## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Duration | 2000ms | Match to actual estimated load time; animated progress that finishes early stalls |-| Easing | ease-out | Decelerating fill feels natural — fast start, slow near 100% |-| Circumference | 201px (r=32) | `2π × r`; scales with radius choice |-| Step count | 5 | 3–7 steps; more than 8 steps individual dots become unreadable |+| Fills to | 100% | How far one play fills: 50%, 75% or 100% |+| Speed | Normal | How long the fill takes: slow is 3.2s, normal 2s and fast 1.2s; in a real app it follows the actual progress |+| Feel | Smooth | Smooth starts fast and slows near the end, which feels natural; Gentle eases in and out; Even fills at one steady pace |+| Sliding bar | off | For waits of unknown length: a short piece slides along the bar instead of filling it |+| Fill color | Blue | The color of the bar, the ring and the steps |## Production notes- **Don't fake progress**: animating to 90% and stalling while waiting for a response (common pattern) is deceptive and erodes trust. Either animate to an honest checkpoint, or use indeterminate mode.- **`transition` vs `rAF`**: CSS `transition` is simpler but can't be paused or reversed mid-flight. `rAF` gives full control — necessary for chunked uploads where progress arrives in bursts.- **Accessibility**: wrap the progress bar in `<progress value="60" max="100">` or add `role="progressbar"`, `aria-valuenow`, `aria-valuemin`, and `aria-valuemax` attributes.-- **GSAP**: `gsap.to(fill, { width: "75%", duration: 2, ease: "power2.out" })`. For circular rings, animate `strokeDashoffset` directly.+- **GSAP**: `gsap.to(fill, { xPercent: -25, duration: 2, ease: "power2.out" })` slides a full-width fill to 75%. For circular rings, animate `strokeDashoffset` directly.- **React**: the HTML `<progress>` element is accessible out of the box. Radix UI's `<Progress>` provides a headless, styled alternative.## See also-- [Loading Spinner](../loading-spinner/) — for unknown-duration loads-- [Skeleton Loader](../skeleton-loader/) — content-shaped placeholder while loading-- [Checkmark Draw](../checkmark-draw/) — success state after progress reaches 100%-- [Progress Bar](../../01-scroll-based/progress-bar/) — scroll-driven reading progress variant+- [Loading Spinner](../loading-spinner/) — a spinner for waits of unknown length+- [Skeleton Loader](../skeleton-loader/) — gray shapes stand in for the content+- [Checkmark Draw](../checkmark-draw/) — the success sign once it reaches the end+- [Progress Bar](../../01-scroll-based/progress-bar/) — a bar that fills as you scrolldiff --git a/animations/04-micro-interactions/progress-animation/index.html b/animations/04-micro-interactions/progress-animation/index.htmlindex cb5748de..b3477984 100644--- a/animations/04-micro-interactions/progress-animation/index.html+++ b/animations/04-micro-interactions/progress-animation/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Progress Animation — Animation Handbook</title>- <meta name="description" content="Linear bar, circular ring, and stepped segments — all driven by a single percentage value.">+ <meta name="description" content="A bar, a ring and steps fill up to show progress. Best for uploads."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/progress-animation/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,91 +12,62 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Progress Animation — Animation Handbook">- <meta property="og:description" content="Linear bar, circular ring, and stepped segments — all driven by a single percentage value.">+ <meta property="og:description" content="A bar, a ring and steps fill up to show progress. Best for uploads."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/progress-animation/"><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="Progress Animation — Animation Handbook">- <meta name="twitter:description" content="Linear bar, circular ring, and stepped segments — all driven by a single percentage value.">+ <meta name="twitter:description" content="A bar, a ring and steps fill up to show progress. Best for uploads."><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": "Progress Animation", "name": "Progress Animation", "description": "Linear bar, circular ring, and stepped segments — all driven by a single percentage value.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/progress-animation/", "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, Progress Animation"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Progress Animation", "name": "Progress Animation", "description": "A bar, a ring and steps fill up to show progress. Best for uploads.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/progress-animation/", "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, Progress Animation"}</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;--prog-dur:2000ms;--prog-color:#58a6ff}+ :root{--ui-accent:#ff9d5c;--ui-border:rgba(255,255,255,.09);--ui-muted:#8a8a92;--prog-dur:2000ms;--prog-color:#58a6ff}*,*::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;flex-direction:column;align-items:center;justify-content:center;gap:32px;padding:32px}- /* Linear bar */+ .stage{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:24px;padding:24px;background:#0b0b0d}+ /* Bar: the fill is as wide as the track and slides in from the left; the track clips the part still outside */.prog-section{width:100%;max-width:320px}- .prog-label{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted);display:flex;justify-content:space-between;margin-bottom:8px}+ .prog-label{font-size:11px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted);display:flex;justify-content:space-between;margin-bottom:8px}.prog-track{height:8px;background:var(--ui-border);border-radius:4px;overflow:hidden}- .prog-fill{height:100%;background:var(--prog-color);width:0%;border-radius:4px}- .prog-fill.indet{width:40%!important;animation:indet var(--prog-dur) ease-in-out infinite;transition:none}+ .prog-fill{height:100%;width:100%;background:var(--prog-color);border-radius:4px;transform:translateX(-100%)}+ .prog-fill.indet{width:40%;animation:indet var(--prog-dur) ease-in-out infinite}@keyframes indet{0%{transform:translateX(-150%)}100%{transform:translateX(350%)}}- /* Circular */- .circle-wrap{display:flex;align-items:center;gap:20px}+ /* Ring */.prog-circle{position:relative;width:80px;height:80px;flex-shrink:0}.prog-circle svg{transform:rotate(-90deg)}.prog-ring{fill:none;stroke:var(--ui-border);stroke-width:6}.prog-arc{fill:none;stroke:var(--prog-color);stroke-width:6;stroke-linecap:round;stroke-dasharray:201;stroke-dashoffset:201}.prog-pct{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:bold}/* Steps */- .steps{display:flex;gap:4px;align-items:center;width:100%;max-width:320px}+ .steps{display:flex;gap:4px;align-items:center}.step{flex:1;height:6px;background:var(--ui-border);border-radius:3px;transition:background 200ms ease}.step.done{background:var(--prog-color)}- .step-labels{display:flex;justify-content:space-between;font-size:9px;color:var(--ui-muted);margin-top:6px}- /* Play btn */- .play-btn{background:var(--ui-accent);color:#000;border:none;font-family:var(--mono);font-size:12px;font-weight:bold;padding:0 24px;height:44px;border-radius:6px;cursor:pointer;min-width:120px}- @media(hover:hover){.play-btn:hover{filter:brightness(1.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:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}- .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}- 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:500px}}- @media(prefers-reduced-motion:reduce){.prog-fill.indet{animation:none!important;width:100%!important}}+ @media(prefers-reduced-motion:reduce){.prog-fill.indet{animation:none!important;width:100%!important;transform: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="../loading-spinner/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../checkmark-draw/" 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/progress-animation/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Progress Animation</h1>- <p>Linear bar, circular ring, and stepped segments — all driven by a single percentage value.</p>-</header>-<div class="layout">- <div class="stage">- <div class="prog-section">- <div class="prog-label"><span>Linear Bar</span><span id="pct-label">0%</span></div>- <div class="prog-track"><div class="prog-fill" id="linear-fill"></div></div>+<body class="hb" data-hb-kind="once" data-hb-autoplay>+<nav class="hb-bar" aria-label="Animation Handbook">+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>+ <span class="hb-pager"><a href="../loading-spinner/" rel="prev" aria-label="Previous: Loading Spinner"><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>Loading Spinner</span></a><a href="../checkmark-draw/" rel="next" aria-label="Next: Checkmark Draw"><span><span class="hb-dir">Next: </span>Checkmark Draw</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.12 · Micro-Interactions</p>+ <h1>Progress Animation</h1>+ <p class="hb-lede">A bar, a ring and steps fill up to show progress. Best for uploads.</p>+ </header>++ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">1</span>+ <div><h2 id="hb-watch-title">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div></div>- <div class="circle-wrap">+ <div class="stage hb-dots" role="img" aria-label="Progress filling to 100%">+ <div class="prog-section">+ <div class="prog-label"><span>Bar</span><span id="pct-label">0%</span></div>+ <div class="prog-track"><div class="prog-fill" id="linear-fill"></div></div>+ </div><div class="prog-circle"><svg width="80" height="80" viewBox="0 0 80 80"><circle class="prog-ring" cx="40" cy="40" r="32"/>@@ -104,38 +75,116 @@ body{padding-top:46px}</svg><div class="prog-pct" id="circ-pct">0%</div></div>- <div style="font-size:11px;color:var(--ui-muted);line-height:1.6;max-width:180px">Circular ring — stroke-dashoffset animates from the full circumference (201px) to 0.</div>+ <div class="prog-section">+ <div class="prog-label"><span>Steps</span><span id="step-label">0 / 5</span></div>+ <div class="steps" id="steps">+ <div class="step"></div><div class="step"></div><div class="step"></div><div class="step"></div><div class="step"></div>+ </div>+ </div>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop autocomplete="off"><span>Loop</span></label>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label></div>- <div style="width:100%;max-width:320px">- <div class="prog-label"><span>Stepped</span><span id="step-label">0 / 5</span></div>- <div class="steps" id="steps">- <div class="step"></div><div class="step"></div><div class="step"></div><div class="step"></div><div class="step"></div>+ </section>++ <section class="hb-step hb-try" aria-labelledby="hb-try-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">2</span>+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and the animation plays again.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="target-lbl">Fills to</p>+ <div class="seg" id="target-seg" role="group" aria-labelledby="target-lbl">+ <button type="button" data-pct="50" aria-pressed="false">50%</button>+ <button type="button" data-pct="75" aria-pressed="false">75%</button>+ <button type="button" data-pct="100" class="on" aria-pressed="true">100%</button>+ </div>+ <p class="hb-hint">How far the progress goes in one play.</p>+ </div>+ <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="3200" aria-pressed="false">Slow</button>+ <button type="button" data-ms="2000" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="1200" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How long the fill takes.</p></div>- <div class="step-labels"><span>Start</span><span>Complete</span></div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="feel-lbl">Feel</p>+ <div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">+ <button type="button" data-ease="ease-out" class="on" aria-pressed="true">Smooth</button>+ <button type="button" data-ease="ease-in-out" aria-pressed="false">Gentle</button>+ <button type="button" data-ease="linear" aria-pressed="false">Even</button>+ </div>+ <p class="hb-hint">Smooth starts fast and eases into the end.</p>+ </div>+ </div>+ <details class="hb-options">+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>+ <div class="hb-settings">+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Sliding bar</span><input class="hb-switch" type="checkbox" role="switch" id="indet-tog" autocomplete="off"></label>+ <p class="hb-hint">For waits of unknown length: the bar slides instead.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="color-lbl">Fill 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">The color of the bar, the ring and the steps.</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>- <button class="play-btn" id="play-btn" aria-label="Start progress">▶ Start</button>- </div>- <aside>- <p class="note">Determinate progress reduces anxiety — users wait calmly when they can see the end. Indeterminate is for unknown durations.</p>- <div class="lbl">Duration</div>- <div class="sr"><input type="range" id="dur-sl" min="500" max="5000" value="2000" step="100"><span class="sv" id="dur-v">2.0s</span></div>- <div class="lbl">Target %</div>- <div class="sr"><input type="range" id="target-sl" min="0" max="100" value="100" step="5"><span class="sv" id="target-v">100%</span></div>- <div class="lbl">Easing</div>- <select id="ease-sel">- <option value="ease-out" selected>Ease out</option>- <option value="linear">Linear</option>- <option value="ease-in-out">Ease in-out</option>- </select>- <div class="lbl">Fill Color</div>- <input type="color" id="color-pick" value="#58a6ff" aria-label="Progress color">- <label class="tog"><input type="checkbox" id="indet-tog"><span>Indeterminate mode (bar)</span></label>- <div class="div"></div>- <p style="font-size:10px;color:var(--ui-muted)">Circumference of r=32 circle ≈ 201px. stroke-dashoffset controls how much arc is hidden.</p>- </aside>-</div>+ <div class="hb-card">+ <p class="hb-prompt">Add a progress indicator to [the upload, download or task whose progress you know]. Show how much is done with a bar that fills from left to right, a ring whose outline fills around the circle, or a row of steps that light up in turn, all driven by the same percentage and shown with the number. Fill it smoothly as progress arrives, and only show real progress: never race to near the end and stall. When the settings ask for it, slide a short piece along the bar for waits of unknown length. If the visitor has reduced motion turned on, jump straight to the current value. 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>Uploads</li><li>Downloads</li><li>Multi-step forms</li><li>Installs</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Unknown waits</li><li>Fake progress</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>- let dur=2000,target=100,running=false,animRaf=null,indetTimer=null;+ const stage=document.querySelector('.stage');const linearFill=document.getElementById('linear-fill');const arc=document.getElementById('prog-arc');const pctLabel=document.getElementById('pct-label');@@ -143,15 +192,30 @@ body{padding-top:46px}const stepEl=document.getElementById('steps');const stepLabel=document.getElementById('step-label');const indetTog=document.getElementById('indet-tog');+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');const steps=[...stepEl.querySelectorAll('.step')];+ const vars=document.documentElement.style;+ const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');const CIRC=201;const EASE={'ease-out':t=>1-(1-t)**3,'linear':t=>t,'ease-in-out':t=>t<.5?4*t*t*t:1-(-2*t+2)**3/2};- let ease=EASE['ease-out'];- const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');+ let dur=2000,target=100,ease=EASE['ease-out'],animRaf=null,timers=[];++ // Slow motion triples the fill and the slide, never the hold or the steps' colour change.+ function speed(){return slowTog.checked?dur*3:dur}+ // Drops a timer's id once it fires, so `timers` only ever holds ones still pending.+ function later(fn,wait){+ const id=setTimeout(()=>{+ const i=timers.indexOf(id);+ if(i>-1)timers.splice(i,1);+ fn();+ },wait);+ timers.push(id);+ }+ // The bar is a full-width fill slid in from the left, so progress moves it with transform.function setProgress(p){const pct=Math.round(p);- linearFill.style.width=p+'%';+ linearFill.style.transform='translateX('+(p-100)+'%)';arc.style.strokeDashoffset=CIRC*(1-p/100);pctLabel.textContent=pct+'%';circPct.textContent=pct+'%';@@ -159,46 +223,60 @@ body{padding-top:46px}steps.forEach((s,i)=>s.classList.toggle('done',i<doneSteps));stepLabel.textContent=doneSteps+' / 5';}-- function startIndet(){+ // Ends any slide and empties all three displays at once; the steps skip their colour change for the reset.+ function resetDisplays(){+ linearFill.classList.remove('indet');+ steps.forEach(s=>{s.style.transition='none'});+ setProgress(0);+ void stepEl.offsetWidth;+ steps.forEach(s=>{s.style.transition=''});+ }+ function startIndet(len){linearFill.classList.add('indet');- clearTimeout(indetTimer);- indetTimer=setTimeout(()=>{linearFill.classList.remove('indet');},dur*2);+ later(()=>{linearFill.classList.remove('indet')},len);}- function startAnim(){- if(animRaf)cancelAnimationFrame(animRaf);- setProgress(0);running=true;- if(indetTog.checked)startIndet();- if(reduceMotion.matches){setProgress(target);running=false;animRaf=null;return;}+ // One play fills the bar, the ring and the steps to the target. With Sliding bar on, the bar also slides for twice+ // the Speed before it shows its fill. While Loop is on, the displays hold 1200ms after the last movement ends+ // (the slide when there is one); Loop is checked then, so switching it off leaves them filled.+ function cycle(){+ cancelAnimationFrame(animRaf);animRaf=null;+ const move=speed();+ vars.setProperty('--prog-dur',move+'ms');+ resetDisplays();+ stage.setAttribute('aria-label','Progress filling to '+target+'%');+ const slide=indetTog.checked;+ if(slide)startIndet(move*2);+ if(reduceMotion.matches){setProgress(target);return}const start=performance.now();function tick(now){- const t=Math.min((now-start)/dur,1);+ const t=Math.min(Math.max((now-start)/move,0),1);setProgress(target*ease(t));- if(t<1){animRaf=requestAnimationFrame(tick);}else{running=false;animRaf=null;}+ animRaf=t<1?requestAnimationFrame(tick):null;}animRaf=requestAnimationFrame(tick);+ later(()=>{+ if(!loopTog.checked||reduceMotion.matches)return;+ cycle();+ },(slide?move*2:move)+1200);}+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}- document.getElementById('play-btn').addEventListener('click',startAnim);- document.getElementById('dur-sl').addEventListener('input',e=>{- dur=+e.target.value;document.getElementById('dur-v').textContent=(dur/1000).toFixed(1)+'s';- document.documentElement.style.setProperty('--prog-dur',dur+'ms');- });- document.getElementById('target-sl').addEventListener('input',e=>{- target=+e.target.value;document.getElementById('target-v').textContent=target+'%';- });- document.getElementById('ease-sel').addEventListener('change',e=>{- ease=EASE[e.target.value]||EASE['ease-out'];- });- document.getElementById('color-pick').addEventListener('input',e=>{- document.documentElement.style.setProperty('--prog-color',e.target.value);- });- indetTog.addEventListener('change',e=>{- if(e.target.checked){if(running)startIndet();}- else{clearTimeout(indetTimer);linearFill.classList.remove('indet');}- });+ document.getElementById('btn-play').addEventListener('click',play);+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});+ function choices(id,pick){+ const buttons=document.querySelectorAll('#'+id+' button');+ buttons.forEach(b=>b.addEventListener('click',()=>{+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});+ pick(b.dataset);+ }));+ }+ choices('target-seg',d=>{target=+d.pct});+ choices('speed-seg',d=>{dur=+d.ms});+ choices('feel-seg',d=>{ease=EASE[d.ease]||EASE['ease-out']});+ choices('color-sw',d=>{vars.setProperty('--prog-color',d.c)});+ vars.setProperty('--prog-dur',speed()+'ms');+ if(reduceMotion.matches)setProgress(target); // reduced motion: the first picture is the finished one</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 2db568c2..9d83af93 100644--- a/index.html+++ b/index.html@@ -962,7 +962,7 @@ const CATS=[['skeleton-loader','Skeleton Loader','Gray shapes hold the place of content while it loads. Best for feeds and cards.'],['shimmer-effect','Shimmer Effect','Gradient sweep over skeleton placeholders — gives the impression of data streaming in.'],['loading-spinner','Loading Spinner','Six spinner variants from a single CSS color and speed — ring, orbit, arc, bounce, pulse, square.'],- ['progress-animation','Progress Animation','Linear bar, circular ring, and stepped segments — all driven by a single percentage value.'],+ ['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.'],['badge-pulse','Notification Badge Pulse','Dot on icon pulses to draw peripheral attention — scale, halo, or both.'],