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
fix: let go of a held Button Press Scale key when the focus moves away
matin352763f29379
diff --git a/animations/04-micro-interactions/button-press-scale/README.md b/animations/04-micro-interactions/button-press-scale/README.mdindex 3e60f0d3..f9378a74 100644--- a/animations/04-micro-interactions/button-press-scale/README.md+++ b/animations/04-micro-interactions/button-press-scale/README.md@@ -34,16 +34,17 @@ Two separate transitions handle press and release with different timings — preconst press = () => btn.classList.add('pressed');const release = () => btn.classList.remove('pressed');-btn.addEventListener('pointerdown', press);+btn.addEventListener('pointerdown', e => { press(); btn.setPointerCapture(e.pointerId); });btn.addEventListener('pointerup', release);btn.addEventListener('pointercancel', () => btn.classList.remove('pressed'));// Keyboard supportbtn.addEventListener('keydown', e => { if (e.key === ' ' || e.key === 'Enter') press() });btn.addEventListener('keyup', e => { if (e.key === ' ' || e.key === 'Enter') release() });+btn.addEventListener('blur', release);```-The asymmetric timing is the key insight: pressing (80ms) mirrors the physical suddenness of contact; releasing (180ms) mirrors the slower mechanical spring-back of a real button.+The asymmetric timing is the key insight: pressing (80ms) mirrors the physical suddenness of contact; releasing (180ms) mirrors the slower mechanical spring-back of a real button. The glow crossfades a resting shadow on `::before` and a pressed shadow on `::after` by opacity, with the same timing as the size, rather than animating `box-shadow` itself, which repaints on every frame.## Key parameters| Parameter | Default | Effect |@@ -54,7 +55,7 @@ The asymmetric timing is the key insight: pressing (80ms) mirrors the physical s| Press speed | Normal | How long the shrink takes: slow is 130ms, normal 80ms and fast 50ms; a press should feel instant |## Production notes-- **`pointercancel` handling**: always listen for `pointercancel` in addition to `pointerup`. If the user starts a scroll gesture after pressing, `pointerup` may not fire, leaving the button stuck in its pressed state.+- **`pointercancel` handling**: always listen for `pointercancel` in addition to `pointerup`. If the user starts a scroll gesture after pressing, `pointerup` may not fire, leaving the button stuck in its pressed state. Two more ways to get stuck are covered in the snippet: without `setPointerCapture` the release is missed when the pointer has moved off the button, and without the `blur` listener a key held down while Tab moves the focus away sends its `keyup` to the next element.- **`touch-action: manipulation`** on the button element suppresses the 300ms tap delay on mobile browsers without needing a separate fast-tap library.- **Shadow pairing**: coupling a shadow-shrink to the scale change increases realism — a button that lifts slightly on hover and drops on press mirrors physical button behavior.- **`prefers-reduced-motion`**: switch the transitions off for users who request reduced motion, so the button changes size at once instead of animating; the demo does this.diff --git a/animations/04-micro-interactions/button-press-scale/index.html b/animations/04-micro-interactions/button-press-scale/index.htmlindex 1809072f..752c7dd3 100644--- a/animations/04-micro-interactions/button-press-scale/index.html+++ b/animations/04-micro-interactions/button-press-scale/index.html@@ -172,13 +172,15 @@const vars=document.documentElement.style;let pd=80,rd=180,runTimers=[];- // A press adds "pressed" (pointer down, or Space and Enter) and letting go removes it (pointer up, cancel, or the key coming up).+ // A press adds "pressed" (pointer down, or Space and Enter) and letting go removes it (pointer up, cancel, the key coming up, or+ // the focus leaving the button: a key held while Tab moves the focus away sends its keyup to the next element).btns.forEach(btn=>{const press=()=>btn.classList.add('pressed');const release=()=>btn.classList.remove('pressed');btn.addEventListener('pointerdown',e=>{press();btn.setPointerCapture(e.pointerId)});btn.addEventListener('pointerup',release);btn.addEventListener('pointercancel',release);+ btn.addEventListener('blur',release);btn.addEventListener('keydown',e=>{if(e.key===' '||e.key==='Enter')press()});btn.addEventListener('keyup',e=>{if(e.key===' '||e.key==='Enter')release()});});diff --git a/docs/superpowers/plans/2026-09-29-micro-content-part1.md b/docs/superpowers/plans/2026-09-29-micro-content-part1.mdindex 2756c031..98705b51 100644--- a/docs/superpowers/plans/2026-09-29-micro-content-part1.md+++ b/docs/superpowers/plans/2026-09-29-micro-content-part1.md@@ -299,7 +299,7 @@ None: leave out the `details.hb-options` block.- **Description:** Shrinks as you press it and springs back as you let go. Best for main buttons.- **Step 1:** Click it — help line: "Press and hold a button, then let go, or press Show me."- **Player bar:** Show me · Slow motion (css). No Reset: a button always returns to full size when it is let go.-- **What the visitor does:** pressing a button adds `pressed` (`pointerdown`, or Space and Enter), and letting go removes it (`pointerup`, or the key coming up), as today; `pointercancel` lets go too. Touch works the same way.+- **What the visitor does:** pressing a button adds `pressed` (`pointerdown`, or Space and Enter), and letting go removes it (`pointerup`, or the key coming up), as today; `pointercancel` lets go too, and so does `blur`: a Space or Enter held down when Tab moves the focus away sends its key-up to the next button, and without `blur` the first button stayed pressed (a change of the final wave). Touch works the same way.- **Show me:** presses each button once, top to bottom (Confirm, Save Draft, Cancel).- Button i (0 to 2) goes down (`pressed` on) with `later(down, i*(pd+rd), i*540)` and comes up with `later(up, i*(pd+rd)+pd, i*540+320)`. `pd` is Press speed and `rd` Release speed: each press shrinks, holds 320ms and springs back, and 220ms pass before the next press.- At the defaults the buttons go down at 0, 800 and 1600ms and come up 400ms later each. The run is at rest by about 2.2 s, or about 3.7 s with Slow motion.@@ -358,8 +358,8 @@ None: leave out the `details.hb-options` block.- [Click / Tap Ripple](../click-ripple/) — a ripple spreads from the spot you press- [Hover State Animation](../hover-state/) — items react before they are clicked- [Checkmark Draw](../checkmark-draw/) — a tick draws itself once the task is done-- **README How it works:** unchanged-- **README Production notes:** the `prefers-reduced-motion` bullet becomes: "**`prefers-reduced-motion`**: switch the transitions off for users who request reduced motion, so the button changes size at once instead of animating; the demo does this." The rest is unchanged.+- **README How it works:** the JS snippet's `pointerdown` handler also captures the pointer, `e => { press(); btn.setPointerCapture(e.pointerId); }`, and the snippet gains `btn.addEventListener('blur', release);` after the key handlers, as the page has them. One sentence after the paragraph on the asymmetric timing says the glow crossfades a resting shadow on `::before` and a pressed shadow on `::after` by opacity, with the same timing as the size, rather than animating `box-shadow`. The rest is unchanged.+- **README Production notes:** the `prefers-reduced-motion` bullet becomes: "**`prefers-reduced-motion`**: switch the transitions off for users who request reduced motion, so the button changes size at once instead of animating; the demo does this." The `pointercancel` bullet gains: "Two more ways to get stuck are covered in the snippet: without `setPointerCapture` the release is missed when the pointer has moved off the button, and without the `blur` listener a key held down while Tab moves the focus away sends its `keyup` to the next element." The rest is unchanged.- **Category line:** `04.04 · Micro-Interactions`- **Pager:** Previous: Focus Ring Animation (`../focus-ring/`) · Next: Magnetic Button (`../magnetic-button/`)