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 hover and focus hold a Toast Notification toast under reduced motion
matin54c7ea0a53d8
diff --git a/animations/04-micro-interactions/toast-notification/README.md b/animations/04-micro-interactions/toast-notification/README.mdindex 60a25e03..b5f5b326 100644--- a/animations/04-micro-interactions/toast-notification/README.md+++ b/animations/04-micro-interactions/toast-notification/README.md@@ -39,7 +39,7 @@ The region is `role="status" aria-live="polite"` so each toast's text is announc- **Announce, don't trap.** Wrap the region in `aria-live="polite"` and `role="status"` so screen readers hear the message; never move focus into a toast — that is dialog behavior, not notification behavior. Errors that demand action belong in an alert, not a toast.- **Cap the stack.** An unbounded stack buries the screen and defeats the purpose. Keep a small limit (3–5) and evict the oldest, or coalesce duplicates into a single count.- **Pause on hover and focus.** A toast that vanishes while being read is hostile. Pausing the progress animation on `:hover`/`:focus-within` pauses the timer too when dismissal is driven by `animationend`.-- **Respect reduced motion.** Under `prefers-reduced-motion: reduce`, drop the slide/scale and the sweeping bar; appear and disappear instantly and fall back to a `setTimeout` for the auto-dismiss so the behavior survives without the animation.+- **Respect reduced motion.** Under `prefers-reduced-motion: reduce`, drop the slide/scale; appear and disappear instantly, and hide the bar but keep its countdown running unseen, so `animationend` still dismisses the toast and hover and focus still pause it.- **Reflow with transforms, never layout.** Animating `top`/`height` to close the gap thrashes layout; FLIP keeps the motion on the GPU-friendly `transform`.- **Library equivalents**: [Sonner](https://sonner.emilkowal.ski/) and `react-hot-toast` provide stacking, swipe, and pause-on-hover out of the box; Radix Toast supplies the accessible primitives (live region, swipe, timers) for a custom skin.diff --git a/animations/04-micro-interactions/toast-notification/index.html b/animations/04-micro-interactions/toast-notification/index.htmlindex 69908d97..bc038ced 100644--- a/animations/04-micro-interactions/toast-notification/index.html+++ b/animations/04-micro-interactions/toast-notification/index.html@@ -52,7 +52,8 @@@container (max-height:300px) or (max-width:323px){.toaster{gap:6px;padding:8px}.toast{padding-top:8px;padding-bottom:8px}}/* A short stage under 760px wide (a phone held sideways) would let a full stack reach the centred button: it steps to the side the stack is not on */@container (max-width:759px) and (max-height:360px){.send,.send.at-top{top:50%;bottom:auto;left:16px;right:auto;transform:translateY(-50%)}.send.at-right{left:auto;right:16px}}- @media(prefers-reduced-motion:reduce){.toast{transition:none!important}.toast .prog{animation:none!important;transform:scaleX(0)}}+ /* Reduced motion: toasts come and go without movement, and the bar is hidden but keeps counting down, so it still ends the toast and hover and focus still pause it */+ @media(prefers-reduced-motion:reduce){.toast{transition:none!important}.toast .prog{visibility:hidden}}</style><link rel="stylesheet" href="../../../assets/css/demo-page.css?v=4"><script src="../../../assets/js/demo-page.js?v=4" defer></script>@@ -213,17 +214,15 @@toasts.push(el);wire(el);play(prev); // in the bottom corners the others rise to make room; in the top corners nothing movesvoid el.offsetWidth;- if(reduceMotion.matches){- el.style.opacity='1';el.style.transform='none';- el._to=setTimeout(()=>dismiss(el),dur*1000); // no bar to end the countdown, so a timer does- }else requestAnimationFrame(()=>{if(el._gone)return;el.style.opacity='1';el.style.transform='none'});+ if(reduceMotion.matches){el.style.opacity='1';el.style.transform='none'}+ else requestAnimationFrame(()=>{if(el._gone)return;el.style.opacity='1';el.style.transform='none'});}// Toasts leave together. Each slides out from where it stands but stops taking room in the stack at once (taken out of the flow at its measured// place, under the others), so the others, measured first, glide into the gap at once instead of waiting for the exit. The timer only removes the node.function leave(going,dir){going=going.filter(el=>el&&!el._gone);if(!going.length)return;- going.forEach(el=>{el._gone=true;clearTimeout(el._to);const i=toasts.indexOf(el);if(i>-1)toasts.splice(i,1)});+ going.forEach(el=>{el._gone=true;const i=toasts.indexOf(el);if(i>-1)toasts.splice(i,1)});if(reduceMotion.matches){going.forEach(el=>el.remove());return}const prev=snap(),top=corner.startsWith('t'),cs=getComputedStyle(toaster),gap=parseFloat(cs.rowGap)||0;const stack=[...toaster.children].filter(t=>t.style.position!=='absolute');@@ -269,7 +268,7 @@send.addEventListener('click',()=>spawn()); // not addEventListener('click',spawn): that would pass the click as the message// Show me starts with no toasts on the stage: every one, the ones still leaving included, is taken away at once (no exit).function toRest(){- toaster.querySelectorAll('.toast').forEach(el=>{el._gone=true;clearTimeout(el._to);clearTimeout(el._exit);el.remove()});+ toaster.querySelectorAll('.toast').forEach(el=>{el._gone=true;clearTimeout(el._exit);el.remove()});toasts=[];}// Show me is one press of the stage's button. It leaves no timer behind (the toast it sends counts itself down and leavesdiff --git a/docs/superpowers/plans/2026-09-29-micro-content-part2.md b/docs/superpowers/plans/2026-09-29-micro-content-part2.mdindex 1318cb2b..ebf2f2ac 100644--- a/docs/superpowers/plans/2026-09-29-micro-content-part2.md+++ b/docs/superpowers/plans/2026-09-29-micro-content-part2.md@@ -952,7 +952,7 @@ None: leave out the `details.hb-options` block.- `hb:input` has nothing to stop.- **Reset:** dismisses every toast, as "Dismiss all" did (each leaves the way it came), after `stopRun()`.- **Slow motion:** none.-- **Reduced motion:** the demo's rules stay: toasts appear and disappear without movement, the bar is hidden, and a timer dismisses each one.+- **Reduced motion:** the demo's rules stay: toasts appear and disappear without movement, and the bar is hidden (`.toast .prog{visibility:hidden}`) but keeps counting down, so its `animationend` still dismisses each toast after Time on screen, and hover, focus inside the toast and a held finger still pause it. This is a change of the final wave: the bar used to be removed (`animation:none`) and a `setTimeout` in `spawn()` dismissed each toast whatever the pointer or the focus was doing, so a toast could go while it was hovered or while a keyboard user was on ×, and the focus fell back to `<body>`. The timer, and the `clearTimeout` calls for it in `leave()` and `toRest()`, are gone. A toast under reduced motion still lives Time on screen (measured 2.5 s and 4 s).- **Touch:** already Pointer Events: a drag past 35% of its width or a tap dismisses a toast. Holding a finger on a toast pauses its countdown (the `paused` class). Pointing at a toast pauses it too, inside `@media (hover: hover)`, as today.- **Stage font:** site font. `.toast .ic` and `.toast .ti` drop `font-family:var(--disp)`; `.toast .x` and the new `.send` get `font-family:inherit`. `.toast .ms` goes up to 11px (was 10.5px).- **Stage:** the corner stack stays.@@ -1008,7 +1008,7 @@ None: leave out the `details.hb-options` block.- [Modal Expand](../modal-expand/) — a window that must be closed before you go on- [Success Confetti](../success-confetti/) — a celebration for a finished task- **README How it works:** unchanged-- **README Production notes:** unchanged+- **README Production notes:** the "Respect reduced motion" bullet says to drop the slide/scale, to appear and disappear instantly, and to hide the bar but keep its countdown running unseen, so `animationend` still dismisses the toast and hover and focus still pause it (it advised a `setTimeout` fallback, which ignores both). The rest is unchanged.- **Category line:** `04.27 · Micro-Interactions`- **Pager:** Previous: Star Rating (`../star-rating/`) · Next: Segmented Control (`../segmented-control/`)