Skip to content

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.

fix: keep Error Shake's arrival press from emptying a password being typed

matin489da196bbf6
diff --git a/animations/04-micro-interactions/error-shake/README.md b/animations/04-micro-interactions/error-shake/README.md
index 726c898a..c3ac8393 100644
--- a/animations/04-micro-interactions/error-shake/README.md
+++ b/animations/04-micro-interactions/error-shake/README.md
@@ -13,12 +13,15 @@ An error shake tells someone that what they entered was not accepted. The field
The field is animated by toggling an `error` class that applies a `@keyframes` translateX wobble. The keyframe swings the element left and right with **decaying amplitude**, then returns to `translateX(0)`. Because only `transform` is animated, it stays on the compositor and never triggers layout:
```css
+/* the default six swings, as the demo's buildShake(6) writes them (values rounded) */
@keyframes shake {
- 10%,90% { transform: translateX(calc(var(--shake-x) * -1)); }
- 20%,80% { transform: translateX(calc(var(--shake-x) * 1)); }
- 30%,50%,70% { transform: translateX(calc(var(--shake-x) * -0.6)); }
- 40%,60% { transform: translateX(calc(var(--shake-x) * 0.6)); }
- 100% { transform: translateX(0); }
+ 0%, 100% { transform: translateX(0); }
+ 14% { transform: translateX(calc(var(--shake-x) * -0.86)); }
+ 29% { transform: translateX(calc(var(--shake-x) * 0.71)); }
+ 43% { transform: translateX(calc(var(--shake-x) * -0.57)); }
+ 57% { transform: translateX(calc(var(--shake-x) * 0.43)); }
+ 71% { transform: translateX(calc(var(--shake-x) * -0.29)); }
+ 86% { transform: translateX(calc(var(--shake-x) * 0.14)); }
}
.field.error input { border-color: var(--err); animation: shake var(--shake-dur) cubic-bezier(.36,.07,.19,.97) both; }
```
diff --git a/animations/04-micro-interactions/error-shake/index.html b/animations/04-micro-interactions/error-shake/index.html
index a2e050e1..cd91e27e 100644
--- a/animations/04-micro-interactions/error-shake/index.html
+++ b/animations/04-micro-interactions/error-shake/index.html
@@ -42,7 +42,7 @@
.field.error .msg{opacity:1;transform:none}
.field.ok input{border-color:var(--ok)}
.field.ok .msg{opacity:1;transform:none;color:var(--ok)}
- /* The decaying horizontal wobble. translateX only -> compositor-friendly. */
+ /* buildShake() rewrites this rule when the page loads, with swings that decay (six by default); this copy only stands in until then. translateX only -> compositor-friendly. */
@keyframes shake{
10%,90%{transform:translateX(calc(var(--shake-x) * -1))}
20%,80%{transform:translateX(calc(var(--shake-x) * 1))}
@@ -262,8 +262,10 @@
parts.forEach(p=>p.style.removeProperty('transition'));
}
// A wrong password appears as dots, the field shakes as it does for a visitor (no submit, no focus, nothing said aloud),
- // and once the shake has run and been seen the field is emptied.
- document.getElementById('btn-demo').addEventListener('click',()=>{
+ // and once the shake has run and been seen the field is emptied. The press the shared script makes on arrival leaves a
+ // visitor who is already in the form alone: it would empty and replace a password being typed.
+ document.getElementById('btn-demo').addEventListener('click',e=>{
+ if(!e.isTrusted&&stage.contains(document.activeElement))return;
stopRun();
toRest();
input.value=DEMO_PASSWORD;
diff --git a/docs/superpowers/plans/2026-09-29-micro-content-part2.md b/docs/superpowers/plans/2026-09-29-micro-content-part2.md
index b2f881f6..8e84119c 100644
--- a/docs/superpowers/plans/2026-09-29-micro-content-part2.md
+++ b/docs/superpowers/plans/2026-09-29-micro-content-part2.md
@@ -580,8 +580,12 @@ None: leave out the `details.hb-options` block.
- [Focus Ring Animation](../focus-ring/) — a ring that follows keyboard focus
- [Button Press Scale](../button-press-scale/) — a button that shrinks as you press it
- [Checkmark Draw](../checkmark-draw/) — the tick that says yes
-- **README How it works:** after the CSS snippet, add: "The demo writes this keyframe rule from JavaScript, so the Number of swings setting can give it as many swings as it asks for, each smaller than the last." The rest is unchanged.
+- **README How it works:** after the CSS snippet, add: "The demo writes this keyframe rule from JavaScript, so the Number of swings setting can give it as many swings as it asks for, each smaller than the last." The rest is unchanged, except that the CSS snippet now shows the six-swing set (final fix wave, below).
- **README Production notes:** unchanged
+- **Final fix wave (after the category review):**
+ - The press the shared script makes on arrival no longer touches a visitor who is already typing. Show me's handler begins `e=>{if(!e.isTrusted&&stage.contains(document.activeElement))return;` (the guard Form Field Morph has), so a password being typed is not emptied and replaced by "abc123". A visitor's own press on Show me still runs the demo.
+ - The comment above the stylesheet's `@keyframes shake` now says what is true: `buildShake()` rewrites the rule when the page loads, with swings that decay (six by default), and the copy in the stylesheet only stands in until then (its 80% and 90% swings return to full size).
+ - README How it works: the CSS snippet is the six-swing decaying set that `buildShake(6)` writes, rounded: 0% and 100% at 0, then 14% −0.86, 29% 0.71, 43% −0.57, 57% 0.43, 71% −0.29 and 86% 0.14 times `--shake-x`. The old snippet swung back to full size at 80% and 90% while the text called the shake decaying.
- **Category line:** `04.21 · Micro-Interactions`
- **Pager:** Previous: Cursor Follower (`../cursor-follower/`) · Next: Swipe to Dismiss (`../swipe-to-dismiss/`)