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: Button Loading States (04.38)
matin207e517a33f8
diff --git a/README.md b/README.mdindex b862b9fc..86e42c31 100644--- a/README.md+++ b/README.md@@ -157,6 +157,7 @@ All 129 techniques, each linked to its live demo.- **[Pull to Refresh](animations/04-micro-interactions/pull-to-refresh/)** — Pulling a list down shows a spinner, then new items. Best for feeds.- **[Hold to Confirm](animations/04-micro-interactions/hold-to-confirm/)** — Fills up while you hold it and acts only once it is full. Best for delete buttons.- **[Expanding Search](animations/04-micro-interactions/expanding-search/)** — A search icon opens into a field you can type in, and closes when done. Best for toolbars.+- **[Button Loading States](animations/04-micro-interactions/button-loading-states/)** — The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.</details>diff --git a/animations/04-micro-interactions/README.md b/animations/04-micro-interactions/README.mdindex 3089fb52..636253ea 100644--- a/animations/04-micro-interactions/README.md+++ b/animations/04-micro-interactions/README.md@@ -37,6 +37,7 @@ Short, user-triggered animations that provide feedback, confirm actions, and com| [Pull to Refresh](pull-to-refresh/) | Pulling a list down shows a spinner, then new items. Best for feeds. || [Hold to Confirm](hold-to-confirm/) | Fills up while you hold it and acts only once it is full. Best for delete buttons. || [Expanding Search](expanding-search/) | A search icon opens into a field you can type in, and closes when done. Best for toolbars. |+| [Button Loading States](button-loading-states/) | The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons. |## Key conceptsdiff --git a/animations/04-micro-interactions/button-loading-states/README.md b/animations/04-micro-interactions/button-loading-states/README.mdnew file mode 100644index 00000000..b3d91ee2--- /dev/null+++ b/animations/04-micro-interactions/button-loading-states/README.md@@ -0,0 +1,66 @@+# Button Loading States++## What it is+Button loading states show, inside the button itself, that a press is being worked on. The label gives way to a spinner, the button cannot be pressed twice, and when the answer comes a tick or a cross says how it went before the label comes back. The button can also shrink into a circle around the spinner, drawn with a clip so that nothing around it moves.++## When to use it+- Save, Send and Submit buttons that wait for a server+- Contact, feedback and sign-up forms+- Checkout and payment buttons, where a second press would order twice+- Any action that takes from about half a second to a few seconds++## How it works+The button keeps its full size in the layout the whole time. What the visitor sees as its shape is a color layer inside it, and the states are classes on the button: `busy`, then `ok` or `err`, and `round` while it is shrunk.++```css+.bg { position: absolute; inset: 0; border-radius: 26px; background-color: #ff9d5c;+ clip-path: inset(0 0 round 26px);+ transition: clip-path 300ms cubic-bezier(.22, 1, .36, 1), background-color 300ms; }+.round .bg { clip-path: inset(0 calc(50% - 26px) round 26px); } /* a 52px circle in the middle */+.ok .bg { background-color: #3fb950; }+.err .bg { background-color: #f85149; }+.busy .spin { opacity: 1; animation: spin .7s linear infinite; } /* turns only while busy */+.ok .tick path, .err .cross path { stroke-dashoffset: 0; } /* paths with pathLength="1", dasharray 1 */+```++```js+function submit() {+ if (state !== 'rest') return; // a second press does nothing+ state = 'busy';+ btn.setAttribute('aria-disabled', 'true'); // not disabled: the keyboard focus stays on the button+ btn.classList.add('busy');+ btn.classList.toggle('round', shrinks && !reducedMotion);+ status.textContent = 'Sending…';+ send().then(ok => { // the demo waits How long it loads instead+ btn.classList.replace('busy', ok ? 'ok' : 'err');+ status.textContent = ok ? 'Feedback sent.' : 'Not sent. Please try again.';+ setTimeout(() => btn.classList.remove('ok', 'err', 'round'), 1300); // the change (300ms), then a second to read it+ });+}+```++The label and the spinner crossfade in place, the tick and the cross draw themselves along their length, and an error restarts a short shake on the button's wrapper. Removing the classes plays everything back to Submit; the button only takes presses again once that is done. The focus ring sits outside the button while it is wide and moves to a circle around it while it is round. Under reduced motion the button keeps its shape, nothing turns or shakes, and the label's words change instead: Sending…, ✓ Sent or ✕ Not sent.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Result | Success | Success shows a tick on green; Error shows a cross on red and gives the button a small shake |+| Speed | Normal | How long the shape, the color and the icon take to change: slow is 500ms, normal 300ms and fast 180ms |+| Shrinks to a circle | On | On clips the button's color into a circle around the spinner; off keeps its full shape and changes only what is inside |+| How long it loads | Medium | How long the spinner turns before the answer: short is 0.7 seconds, medium 1.2 and long 2.2; in a real form this is the server's time |++## Production notes+- **`aria-disabled`, not `disabled`**: a button that becomes `disabled` while it has the focus drops the focus to the page, and keyboard users lose their place. Keep it focusable, mark it `aria-disabled="true"` and ignore presses in your handler.+- **Announce it**: the spinner and the icons are visual only. A `role="status"` region that says "Sending…" and then the result tells screen reader users what happened.+- **Do not flash it**: if most answers come back in under about 300ms, start the loading look only after that delay, or it flickers on every fast press.+- **Say what failed**: a cross says that it failed, not why. Keep a message near the form for errors the visitor can fix, and leave what they typed in place.+- **Long waits**: past a few seconds a spinner in a button feels stuck. Use a progress bar for uploads and other long tasks.+- **Never animate the width**: the button's place in the layout keeps its size, so the form does not jump while it shrinks; only the clip and the color layer change.+- **GSAP**: `gsap.to(bg, { clipPath: "inset(0% 41% 0% 41% round 26px)", duration: 0.3, ease: "power3.out" })`, with the starting clip written in the same percentages.+- **Framer Motion**: `<motion.span animate={{ clipPath: busy ? "inset(0% 41% 0% 41% round 26px)" : "inset(0% 0% 0% 0% round 26px)" }} />` on the color layer, and `AnimatePresence` to swap the label, the spinner and the icons.++## See also+- [Checkmark Draw](../checkmark-draw/) — a tick that draws itself once a task succeeds+- [Loading Spinner](../loading-spinner/) — six small shapes that show something is loading+- [Error Shake](../error-shake/) — a shake that says the input was wrong+- [Button Press Scale](../button-press-scale/) — the button shrinks while it is presseddiff --git a/animations/04-micro-interactions/button-loading-states/index.html b/animations/04-micro-interactions/button-loading-states/index.htmlnew file mode 100644index 00000000..9432006a--- /dev/null+++ b/animations/04-micro-interactions/button-loading-states/index.html@@ -0,0 +1,274 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Button Loading States — Animation Handbook</title>+ <meta name="description" content="The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-loading-states/">+ <link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">+ <link rel="icon" type="image/svg+xml" href="../../../favicon.svg">+ <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">+ <meta property="og:type" content="article">+ <meta property="og:site_name" content="Animation Handbook">+ <meta property="og:title" content="Button Loading States — Animation Handbook">+ <meta property="og:description" content="The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-loading-states/">+ <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="Button Loading States — Animation Handbook">+ <meta name="twitter:description" content="The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.">+ <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": "Button Loading States", "name": "Button Loading States", "description": "The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-loading-states/", "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, Button Loading States"}</script>+ <style>+ :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-muted:#9a9aa2;--ink:#0b0b0d;--ok:#3fb950;--err:#f85149;--dur:300ms;--ease:cubic-bezier(.22,1,.36,1)}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ .stage{display:flex;align-items:center;justify-content:center;padding:16px;background:#0b0b0d}+ .card{width:100%;max-width:320px;display:flex;flex-direction:column;gap:14px;padding:20px;border:1px solid var(--ui-border);border-radius:12px;background:var(--ui-bg)}+ .title{font-size:15px;font-weight:700}+ .msg{padding:12px 14px;border-radius:8px;background:#1b1b20;font-size:14px;line-height:1.45;color:#d6d6da}+ .shaker.shake{animation:shake .4s cubic-bezier(.36,.07,.19,.97)}+ @keyframes shake{20%{transform:translateX(-7px)}40%{transform:translateX(6px)}60%{transform:translateX(-4px)}80%{transform:translateX(2px)}}+ /* The button keeps its full size in the layout. What it looks like is the .bg layer: a clip shrinks it to a circle (round),+ so nothing around the button moves, and its color crossfades to green or red with the result. */+ .sbtn{position:relative;display:grid;place-items:center;width:100%;height:52px;border:0;background:none;color:var(--ink);font:inherit;font-size:15px;font-weight:700;cursor:pointer;transition:transform .12s ease}+ .sbtn:active:not([aria-disabled="true"]),.sbtn.down{transform:scale(.97)}+ .sbtn[aria-disabled="true"]{cursor:default}+ .bg{position:absolute;inset:0;border-radius:26px;background-color:var(--ui-accent);clip-path:inset(0 0 round 26px);transition:clip-path var(--dur) var(--ease),background-color var(--dur) var(--ease)}+ .sbtn.round .bg{clip-path:inset(0 calc(50% - 26px) round 26px)}+ .sbtn.ok .bg{background-color:var(--ok)}+ .sbtn.err .bg{background-color:var(--err)}+ /* The words: Submit at rest. The other three show only under reduced motion, where they take the icons' place. */+ .words{position:relative;display:grid}+ .words span{grid-area:1/1;text-align:center;white-space:nowrap;transition:opacity var(--dur) var(--ease)}+ .l-busy,.l-ok,.l-err,.sbtn:is(.busy,.ok,.err) .l-rest{opacity:0}+ .ico{position:absolute;inset:0;display:grid;place-items:center;pointer-events:none}+ .ico>*{grid-area:1/1}+ .spin{width:22px;height:22px;border-radius:50%;border:3px solid rgba(11,11,13,.25);border-top-color:var(--ink);opacity:0;transition:opacity var(--dur) var(--ease)}+ /* The spinner turns only while the button is busy, so nothing on the stage moves at rest */+ .sbtn.busy .spin{opacity:1;animation:spin .7s linear infinite}+ @keyframes spin{to{transform:rotate(360deg)}}+ .ico svg{width:26px;height:26px;fill:none;stroke:var(--ink);stroke-width:3;stroke-linecap:round;stroke-linejoin:round}+ .ico path{stroke-dasharray:1;stroke-dashoffset:1;transition:stroke-dashoffset var(--dur) var(--ease)}+ .sbtn.ok .tick path,.sbtn.err .cross path{stroke-dashoffset:0}+ .sbtn.err .cross path+path{transition-delay:calc(var(--dur)*.4)}+ /* Focus: a ring outside the button (its color layer would cover the site's inward ring), and around the circle once it is round */+ .hb-page .stage .sbtn:focus-visible{outline-color:#f4f4f2;outline-offset:3px}+ .hb-page .stage .sbtn.round:focus-visible{outline-color:transparent}+ .ring{position:absolute;top:-5px;bottom:-5px;left:calc(50% - 31px);width:62px;border:2px solid #f4f4f2;border-radius:50%;opacity:0;pointer-events:none}+ .sbtn.round:focus-visible .ring{opacity:1}+ .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}+ /* Reduced motion: the button keeps its shape, nothing turns or shakes, and the words say what the icons would show */+ @media(prefers-reduced-motion:reduce){+ .sbtn,.bg,.words span,.spin,.ico path{transition:none!important}+ .sbtn .bg,.sbtn.round .bg{clip-path:none}+ .ico{display:none}+ .shaker.shake{animation:none}+ .sbtn.busy .l-busy,.sbtn.ok .l-ok,.sbtn.err .l-err{opacity:1}+ }+ </style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=6">+ <script src="../../../assets/js/demo-page.js?v=6" defer></script>+</head>+<body class="hb" data-hb-kind="do" 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="../expanding-search/" rel="prev" aria-label="Previous: Expanding Search"><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>Expanding Search</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">04.38 · Micro-Interactions</p>+ <h1>Button Loading States</h1>+ <p class="hb-lede">The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.</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">Click it</h2><p>Click or tap Submit and wait for the answer, or press Show me.</p></div>+ </div>+ <div class="stage hb-dots">+ <div class="card">+ <p class="title">Send feedback</p>+ <p class="msg">The new dashboard is much faster. Thank you!</p>+ <div class="shaker" id="shaker">+ <button class="sbtn" id="sbtn" type="button">+ <span class="bg" aria-hidden="true"></span>+ <span class="words"><span class="l-rest">Submit</span><span class="l-busy" aria-hidden="true">Sending…</span><span class="l-ok" aria-hidden="true">✓ Sent</span><span class="l-err" aria-hidden="true">✕ Not sent</span></span>+ <span class="ico" aria-hidden="true">+ <span class="spin"></span>+ <svg class="tick" viewBox="0 0 24 24"><path pathLength="1" d="M5 12.5l4.5 4.5L19 7.5"/></svg>+ <svg class="cross" viewBox="0 0 24 24"><path pathLength="1" d="M7 7l10 10"/><path pathLength="1" d="M17 7 7 17"/></svg>+ </span>+ <span class="ring" aria-hidden="true"></span>+ </button>+ </div>+ </div>+ <p class="sr-only" id="status" role="status" aria-live="polite"></p>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-demo" data-hb-demo><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>Show me</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, then try it again or press Show me.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="result-lbl">Result</p>+ <div class="seg" id="result-seg" role="group" aria-labelledby="result-lbl">+ <button type="button" data-r="ok" class="on" aria-pressed="true">Success</button>+ <button type="button" data-r="err" aria-pressed="false">Error</button>+ </div>+ <p class="hb-hint">Error shows a cross on red and a small shake.</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="500" aria-pressed="false">Slow</button>+ <button type="button" data-ms="300" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="180" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How quickly the shape, the color and the icon change.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Shrinks to a circle</span><input class="hb-switch" type="checkbox" role="switch" id="round-tog" checked autocomplete="off"></label>+ <p class="hb-hint">Off keeps the button's shape and changes only what is inside.</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">+ <p class="hb-setting-name" id="wait-lbl">How long it loads</p>+ <div class="seg" id="wait-seg" role="group" aria-labelledby="wait-lbl">+ <button type="button" data-ms="700" aria-pressed="false">Short</button>+ <button type="button" data-ms="1200" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-ms="2200" aria-pressed="false">Long</button>+ </div>+ <p class="hb-hint">How long the spinner turns before the answer comes.</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 loading states to [the button that sends a form or saves something]. When it is pressed, fade its label out, show a spinner in its place and ignore further presses until it is done. When the answer comes, swap the spinner for a tick, or for a cross with a short shake if it failed, then bring the label back after a moment. When the settings ask for it, shrink the button's colored shape into a circle around the spinner with a clip, never by animating its width, so nothing around it moves. Announce each change to screen readers. If the visitor has reduced motion turned on, keep the shape and change the label's words instead. 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>Save buttons</li><li>Contact forms</li><li>Checkout</li><li>Sign-up forms</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Instant actions</li><li>Long uploads</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 $=id=>document.getElementById(id);+ const btn=$('sbtn'),shaker=$('shaker'),statusEl=$('status'),roundTog=$('round-tog'),slowTog=$('slow-tog');+ const reduceMq=matchMedia('(prefers-reduced-motion:reduce)');+ const vars=document.documentElement.style;+ // Everything that eases between two looks; toRest() switches these transitions off for a moment+ const easing=[btn,...btn.querySelectorAll('.bg,.words span,.spin,.ico path')];+ let result='ok',dur=300,waitMs=1200,state='rest',seqTimers=[],runTimers=[],quiet=false;++ // wait(fn, move, hold) runs fn after move*(slow?3:1) + hold ms: Slow motion triples the movement, never the hold.+ function wait(list,fn,move,hold){+ const id=setTimeout(()=>{list.splice(list.indexOf(id),1);fn()},move*(slowTog.checked?3:1)+hold);+ list.push(id);+ }+ function say(text){if(!quiet)statusEl.textContent=text}+ // Pressed: the label goes, the spinner turns (in a circle when Shrinks to a circle is on) and further presses are ignored. After+ // the shape change and How long it loads, the answer comes. Show me's press comes through here too, but says nothing aloud.+ function submit(fromRun){+ if(state!=='rest')return;+ state='busy';quiet=fromRun;+ btn.setAttribute('aria-disabled','true');+ btn.classList.add('busy');+ btn.classList.toggle('round',roundTog.checked&&!reduceMq.matches);+ say('Sending…');+ wait(seqTimers,answer,dur,waitMs);+ }+ // The answer: a tick on green, or a cross on red with a shake (Result). It shows for a second, then the label comes back.+ function answer(){+ state=result;+ btn.classList.remove('busy');btn.classList.add(result);+ if(result==='err'&&!reduceMq.matches){shaker.classList.remove('shake');void shaker.offsetWidth;shaker.classList.add('shake')}+ say(result==='ok'?'Feedback sent.':'Not sent. Please try again.');+ wait(seqTimers,back,dur,1000);+ }+ function back(){+ btn.classList.remove('ok','err','round');+ wait(seqTimers,()=>{state='rest';btn.removeAttribute('aria-disabled')},dur,0);+ }+ shaker.addEventListener('animationend',()=>shaker.classList.remove('shake'));+ btn.addEventListener('click',()=>submit(false));++ // Show me: one run at a time. Its own timers (the press) go in runTimers; the answer and the way back then follow by themselves.+ function running(){return runTimers.length>0}+ function stopRun(){runTimers.forEach(clearTimeout);runTimers=[];btn.classList.remove('down')}+ // A run starts from Submit at rest, put there without animating: the transitions are turned off, the state is cleared, a+ // reflow makes it stick, and the transitions come back.+ function toRest(){+ seqTimers.forEach(clearTimeout);seqTimers=[];+ easing.forEach(el=>{el.style.transition='none'});+ btn.classList.remove('busy','ok','err','round','down');shaker.classList.remove('shake');+ btn.removeAttribute('aria-disabled');statusEl.textContent='';state='rest';+ void btn.offsetWidth;+ easing.forEach(el=>{el.style.transition=''});+ }+ // The button is pressed down at 150ms and let go at 270ms. At the defaults the answer shows at 1.8 s and Submit is back at 3.4 s.+ // The arrival press leaves alone a Submit the visitor has already pressed.+ $('btn-demo').addEventListener('click',e=>{+ if(!e.isTrusted&&state!=='rest')return;+ stopRun();toRest();+ wait(runTimers,()=>btn.classList.add('down'),0,150);+ wait(runTimers,()=>{btn.classList.remove('down');submit(true)},0,270);+ });+ // The visitor pressed, typed, scrolled or touched inside the stage: the press of the run is called off. A submit that has+ // started finishes as usual.+ document.addEventListener('hb:input',()=>{if(running())stopRun()});++ 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('result-seg',d=>{result=d.r});+ choices('speed-seg',d=>{dur=+d.ms;vars.setProperty('--dur',dur+'ms')});+ choices('wait-seg',d=>{waitMs=+d.ms});+</script>+</body>+</html>diff --git a/animations/04-micro-interactions/expanding-search/index.html b/animations/04-micro-interactions/expanding-search/index.htmlindex 5818231a..9cc33de4 100644--- a/animations/04-micro-interactions/expanding-search/index.html+++ b/animations/04-micro-interactions/expanding-search/index.html@@ -76,7 +76,7 @@<body class="hb" data-hb-kind="do" 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="../hold-to-confirm/" rel="prev" aria-label="Previous: Hold to Confirm"><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>Hold to Confirm</span></a></span>+ <span class="hb-pager"><a href="../hold-to-confirm/" rel="prev" aria-label="Previous: Hold to Confirm"><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>Hold to Confirm</span></a><a href="../button-loading-states/" rel="next" aria-label="Next: Button Loading States"><span><span class="hb-dir">Next: </span>Button Loading States</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">diff --git a/index.html b/index.htmlindex b1179ba0..406e570a 100644--- a/index.html+++ b/index.html@@ -699,6 +699,20 @@ button,input{font:inherit;color:inherit}@keyframes xs-fd{0%,14%{transform:scaleX(.16);opacity:0}17%{opacity:1}26%,74%{transform:scaleX(1);opacity:1}83%{transform:scaleX(.16);opacity:1}86%,100%{transform:scaleX(.16);opacity:0}}@keyframes xs-ln{0%,14%{opacity:1}22%,78%{opacity:0}86%,100%{opacity:1}}@keyframes xs-tx{0%,30%{transform:scaleX(0)}48%,74%{transform:scaleX(1)}76%,100%{transform:scaleX(0)}}+/* button loading states: Submit gives way to a circle with a spinner, which turns green with a tick, then Submit comes back */+.pv-btnload{background:#08090c;display:grid;place-items:center}+.pv-btnload .bw{display:grid;place-items:center;width:62%;max-width:180px;height:24%}+.pv-btnload .bw>*{grid-area:1/1}+.pv-btnload .pl{width:100%;height:100%;display:grid;place-items:center;border-radius:999px;background:var(--accent);color:#0b0b0d;font-family:var(--text);font-size:10px;font-weight:700;letter-spacing:.06em;animation:bl-pl 4s var(--ease) infinite}+.pv-btnload .cc,.pv-btnload .gc{height:100%;aspect-ratio:1;border-radius:50%;background:var(--accent);animation:bl-cc 4s var(--ease) infinite}+.pv-btnload .gc{background:#3fb950;animation-name:bl-gc}+.pv-btnload .sp{height:46%;aspect-ratio:1;border-radius:50%;border:2px solid rgba(11,11,13,.25);border-top-color:#0b0b0d;animation:bl-sp 4s linear infinite}+.pv-btnload .tk{height:56%;aspect-ratio:1;fill:none;stroke:#0b0b0d;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;animation:bl-tk 4s var(--ease) infinite}+@keyframes bl-pl{0%,12%{transform:scaleX(1);opacity:1}22%,78%{transform:scaleX(.3);opacity:0}90%,100%{transform:scaleX(1);opacity:1}}+@keyframes bl-cc{0%,12%{transform:scale(.8);opacity:0}20%,80%{transform:scale(1);opacity:1}88%,100%{transform:scale(.8);opacity:0}}+@keyframes bl-gc{0%,54%{transform:scale(1);opacity:0}58%{opacity:1}61%{transform:scale(1.08)}65%,80%{transform:scale(1);opacity:1}88%,100%{transform:scale(.8);opacity:0}}+@keyframes bl-sp{0%,18%{transform:rotate(0);opacity:0}22%{opacity:1}54%{transform:rotate(810deg);opacity:1}57%,100%{transform:rotate(810deg);opacity:0}}+@keyframes bl-tk{0%,56%{transform:scale(.5);opacity:0}62%,80%{transform:scale(1);opacity:1}86%,100%{transform:scale(1);opacity:0}}/* ── bespoke: 05 Text & Typography ── */.pv-kinetic{background:#0c0608;display:grid;place-items:center;overflow:hidden}@@ -1032,7 +1046,7 @@ button,input{font:inherit;color:inherit}<section class="wrap home-hero" aria-labelledby="hero-title"><span class="float fl1" aria-hidden="true"></span><span class="float fl2" aria-hidden="true"></span><span class="float fl3" aria-hidden="true"></span><span class="float fl4" aria-hidden="true"></span><span class="float fl5" aria-hidden="true"></span><span class="float fl6" aria-hidden="true"></span>- <p class="pill"><span class="pill-dot" aria-hidden="true"></span>131 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>132 free animations · no coding needed</p><h1 class="h1" id="hero-title">What do you want to animate?</h1><p class="sub">Pick a place, or describe it in your own words. Every animation plays live, and each one comes with a ready-made prompt for your AI assistant.</p><form class="search" id="search-form" role="search" action="./" method="get">@@ -1089,8 +1103,8 @@ button,input{font:inherit;color:inherit}<p class="empty-s">Try a simpler word, or pick one of these:</p><p class="pop"><button type="button" data-q="fade in">fade in</button><button type="button" data-q="typing text">typing text</button><button type="button" data-q="loading spinner">loading spinner</button><button type="button" data-q="parallax">parallax</button><button type="button" data-q="confetti">confetti</button></p></div>- <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 131 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>- <noscript><p class="noscript">This page shows its animations with JavaScript. All 131 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript>+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 132 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>+ <noscript><p class="noscript">This page shows its animations with JavaScript. All 132 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript></section><section class="how" id="how" aria-labelledby="how-title">@@ -1108,7 +1122,7 @@ button,input{font:inherit;color:inherit}<footer class="wrap foot"><a class="brand" href="./"><svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><circle class="ring" cx="11.16" cy="20.84" r="6.1"/><circle class="ring" cx="15.12" cy="16.88" r="6.1"/><circle class="ring" cx="18.51" cy="13.49" r="6.1"/><circle class="ball" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>- <p class="foot-t">131 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">132 web animations with live demos and copyable prompts.</p><nav class="nav" aria-label="Footer"><a class="lnk" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener noreferrer">GitHub</a><a class="lnk" href="#top">Back to top</a></nav></footer><div class="toast" id="toast" role="status" aria-live="polite"><span class="ok" aria-hidden="true"><svg class="i" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span><span class="toast-t"></span></div>@@ -1232,6 +1246,7 @@ const CATS=[['pull-to-refresh','Pull to Refresh','Pulling a list down shows a spinner, then new items. Best for feeds.'],['hold-to-confirm','Hold to Confirm','Fills up while you hold it and acts only once it is full. Best for delete buttons.'],['expanding-search','Expanding Search','A search icon opens into a field you can type in, and closes when done. Best for toolbars.'],+ ['button-loading-states','Button Loading States','The button turns into a spinner while it works, then a tick or a cross. Best for Save buttons.'],]},{@@ -1311,7 +1326,7 @@ const PV={'svg-line-draw':'linedraw','scrollspy-nav':'spy','scroll-background-color':'bgblend','hamburger-menu-toggle':'hamb','theme-toggle-morph':'thememorph','copy-to-clipboard':'copyfx','star-rating':'stars','toast-notification':'toast','segmented-control':'segct','pull-to-refresh':'pullref',- 'hold-to-confirm':'holdconf','expanding-search':'xsearch',+ 'hold-to-confirm':'holdconf','expanding-search':'xsearch','button-loading-states':'btnload','flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv','parallax-depth-of-field':'dof','parallax-scrolling':'plx','reverse-scrolling-columns':'revcol','cover-card-to-fixed-header':'cover','fly-in-fly-out-contact-list':'flylist','stacking-cards':'stack',@@ -1435,6 +1450,7 @@ const PLACES={'pull-to-refresh':['load'],'hold-to-confirm':['btn'],'expanding-search':['menu','btn'],+ 'button-loading-states':['btn','load'],// 05'kinetic-typography':['text','intro'],'typewriter-effect':['text','intro'],@@ -1499,6 +1515,7 @@ function pvMarkup(k){case 'sig4': return '<span class="s4r anim"></span><span class="s4r r2 anim"></span><span class="s4r r3 anim"></span><span class="s4d"></span>';case 'holdconf': return '<span class="btn anim"><span class="fl anim"></span><span class="t t1 anim">HOLD TO DELETE</span><span class="t t2 anim">✓ DELETED</span></span>';case 'xsearch': return '<span class="tb"><i class="br"></i><span class="ln anim"><i></i><i></i><i></i></span><span class="fd anim"><i class="tx anim"></i></span><svg class="ic" viewBox="0 0 24 24"><circle cx="11" cy="11" r="6"/><path d="m19.5 19.5-4-4"/></svg></span><span class="pg"><i></i><i></i></span>';+ case 'btnload': return '<span class="bw"><span class="pl anim">SUBMIT</span><span class="cc anim"></span><span class="gc anim"></span><span class="sp anim"></span><svg class="tk anim" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span>';case 'sig5': return '<span class="s5 anim"></span><span class="s5 anim"></span><span class="s5 anim"></span>';case 'sig6': return '<div class="cube anim"><span class="face f1"></span><span class="face f2"></span><span class="face f3"></span><span class="face f4"></span><span class="face f5"></span><span class="face f6"></span></div>';case 'sig7': return '<span class="s7 anim"></span>';diff --git a/sitemap.xml b/sitemap.xmlindex aa0163af..6a474d2f 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -83,6 +83,7 @@<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/pull-to-refresh/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/hold-to-confirm/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/expanding-search/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/button-loading-states/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/kinetic-typography/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/typewriter-effect/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/scramble-text/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>