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 Error Shake to the guided-steps page
matin5bbdd8c7cfbb
diff --git a/animations/04-micro-interactions/error-shake/README.md b/animations/04-micro-interactions/error-shake/README.mdindex 14bfa7ef..726c898a 100644--- a/animations/04-micro-interactions/error-shake/README.md+++ b/animations/04-micro-interactions/error-shake/README.md@@ -1,7 +1,7 @@# Error Shake## What it is-An error shake is a validation-feedback pattern: when a user submits an invalid value, the offending field wobbles horizontally a few times and settles back to center, usually alongside a red border and an inline message. The motion is short, decaying, and purely on the X axis — a visual analogue of a human shaking their head "no."+An error shake tells someone that what they entered was not accepted. The field swings left and right a few times, each swing smaller than the last, then settles exactly where it started, like a head shaking no. A red border and a short message come with it and say what went wrong.## When to use it- Login and sign-up forms on a failed or empty submit@@ -23,6 +23,8 @@ The field is animated by toggling an `error` class that applies a `@keyframes` t.field.error input { border-color: var(--err); animation: shake var(--shake-dur) cubic-bezier(.36,.07,.19,.97) both; }```+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 one JS gotcha: re-adding the class on an element that already has it won't replay the animation. Force a reflow between removing and re-adding so the browser restarts it:```js@@ -39,11 +41,9 @@ A decaying shake reads as "no" universally because it *returns to origin*. Motio## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Shake intensity | 8px | Peak X displacement. Under 4px is barely legible; over ~16px feels violent |-| Oscillations | 6 | Number of left-right swings. 4–6 reads as a headshake; more feels frantic |-| Duration | 400ms | Total wobble time. Under 250ms feels twitchy; over 600ms drags |-| Easing | `cubic-bezier(.36,.07,.19,.97)` | Snappy in/out so swings feel sharp, not floaty |-| Error color | `#f4515b` | Border + message color; pair with text, never rely on color alone |+| Shake distance | Medium | How far the field swings: small is 4px, medium 8px and large 14px; under 4px barely shows and over about 16px feels violent |+| Number of swings | Medium | How many times it swings: few is 4, medium 6 and many 8; four to six reads as a head shake, more feels frantic |+| Speed | Normal | How long the whole shake lasts: slow is 650ms, normal 400ms and fast 250ms; under 250ms feels twitchy and over 600ms drags |## Production notes- **Don't rely on motion or color alone.** The shake and red border are reinforcement; the inline text message is what conveys *why* it failed. Color-blind and reduced-motion users need the words.@@ -54,7 +54,7 @@ A decaying shake reads as "no" universally because it *returns to origin*. Motio- **Library equivalents**: Framer Motion expresses this as `animate={{ x: [0,-8,8,-5,5,0] }}` on a keyframe array; GSAP ships a dedicated `RoughEase` and you can also `gsap.fromTo(el,{x:-8},{x:0,ease:'elastic'})`. Both are the same translateX-keyframe idea with nicer restart ergonomics.## See also-- [Form Field Morph](../form-field-morph/) — the valid-state transition counterpart to a rejection-- [Focus Ring](../focus-ring/) — the other key input-affordance micro-interaction-- [Button Press Scale](../button-press-scale/) — press feedback on the submit button that triggers validation-- [Checkmark Draw](../checkmark-draw/) — the "yes" success motion that a shake is the opposite of+- [Form Field Morph](../form-field-morph/) — a label that rises out of the field as you use it+- [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 yesdiff --git a/animations/04-micro-interactions/error-shake/index.html b/animations/04-micro-interactions/error-shake/index.htmlindex 3f299074..7a30d1a1 100644--- a/animations/04-micro-interactions/error-shake/index.html+++ b/animations/04-micro-interactions/error-shake/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Error Shake — Animation Handbook</title>- <meta name="description" content="Invalid input triggers a decaying horizontal wobble plus a red border — a universal "no".">+ <meta name="description" content="A field shakes side to side when the input is wrong. Best for sign-in forms."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/error-shake/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,39 +12,32 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Error Shake — Animation Handbook">- <meta property="og:description" content="Invalid input triggers a decaying horizontal wobble plus a red border — a universal "no".">+ <meta property="og:description" content="A field shakes side to side when the input is wrong. Best for sign-in forms."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/error-shake/"><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="Error Shake — Animation Handbook">- <meta name="twitter:description" content="Invalid input triggers a decaying horizontal wobble plus a red border — a universal "no".">+ <meta name="twitter:description" content="A field shakes side to side when the input is wrong. Best for sign-in forms."><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": "Error Shake", "name": "Error Shake", "description": "Invalid input triggers a decaying horizontal wobble plus a red border — a universal \"no\".", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/error-shake/", "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, Error Shake"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Error Shake", "name": "Error Shake", "description": "A field shakes side to side when the input is wrong. Best for sign-in forms.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/error-shake/", "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, Error Shake"}</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;--err:#f4515b;--ok:#3fb950;--shake-x:8px;--shake-osc:6;--shake-dur:400ms}+ :root{--bg:#0b0b0d;--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-text:#f4f4f2;--ui-muted:#8a8a92;--err:#f4515b;--ok:#3fb950;--shake-x:8px;--shake-dur:400ms}*,*::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;align-items:center;justify-content:center;padding:32px}+ .stage{display:flex;align-items:center;justify-content:center;padding:clamp(16px,4vw,32px);background:var(--bg)}/* Login card */.card{width:100%;max-width:320px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:12px;padding:24px;display:flex;flex-direction:column;gap:14px}- .card h2{font-family:var(--disp);font-weight:700;font-size:15px}- .card .hint{font-size:10px;color:var(--ui-muted);line-height:1.5}+ .card-title{font-weight:700;font-size:15px}.field{display:flex;flex-direction:column;gap:6px}- .field label{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted)}- .field input{background:var(--bg);border:1.5px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:13px;padding:11px 12px;border-radius:7px;width:100%;min-height:44px;outline:none;transition:border-color .18s}+ .field label{font-size:11px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted)}+ .field input{background:var(--bg);border:1.5px solid var(--ui-border);color:var(--ui-text);font-family:inherit;font-size:13px;padding:11px 12px;border-radius:7px;width:100%;min-height:44px;outline:none;transition:border-color .18s}+ .field input::placeholder{color:var(--ui-muted);opacity:1}.field input:focus{border-color:var(--ui-accent)}+ /* The field draws its own focus (the border), so the site ring is switched off; .stage in front outranks it (0,3,1) */+ .stage .field input:focus-visible{outline:none}/* Error state: red border + shake keyframe */.field.error input{border-color:var(--err)}.field.error input{animation:shake var(--shake-dur) cubic-bezier(.36,.07,.19,.97) both}- .msg{font-size:10.5px;min-height:14px;color:var(--err);opacity:0;transform:translateY(-2px);transition:opacity .18s,transform .18s}+ .msg{font-size:11px;min-height:14px;color:var(--err);opacity:0;transform:translateY(-2px);transition:opacity .18s,transform .18s}.field.error .msg{opacity:1;transform:none}.field.ok input{border-color:var(--ok)}.field.ok .msg{opacity:1;transform:none;color:var(--ok)}@@ -56,73 +49,139 @@40%,60%{transform:translateX(calc(var(--shake-x) * 0.6))}100%{transform:translateX(0)}}- .submit{background:var(--ui-accent);border:none;color:#1a0f08;font-family:var(--disp);font-weight:700;font-size:12px;padding:13px;border-radius:7px;cursor:pointer;min-height:44px;transition:filter .15s}+ .submit{background:var(--ui-accent);border:none;color:#1a0f08;font-family:inherit;font-weight:700;font-size:12px;padding:13px;border-radius:7px;cursor:pointer;min-height:44px;transition:filter .15s}@media(hover:hover){.submit:hover{filter:brightness(1.08)}}.submit:active{filter:brightness(.94)}- 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)}- .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}- .sval{width:52px;text-align:right;color:var(--ui-text)}- .div{height:1px;background:var(--ui-border)}- .replay{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}- @media(hover:hover){.replay:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}+ /* The button is filled with the accent colour, so the site ring (the same colour) would vanish on it: a dark ring instead */+ .hb-page .stage .submit:focus-visible{outline-color:#0b0b0d}+ /* Read out by screen readers only */+ .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}+ /* Phones zoom the page in on a field with type smaller than 16px */+ @media(pointer:coarse){.field input{font-size:16px}}@media(prefers-reduced-motion:reduce){.field.error input{animation: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=4">+ <script src="../../../assets/js/demo-page.js?v=4" 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="../cursor-follower/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../swipe-to-dismiss/" 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/error-shake/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Error Shake</h1>- <p>Invalid input triggers a decaying horizontal wobble plus a red border — a universal "no".</p>-</header>-<div class="layout">- <div class="stage">- <form class="card" id="login" novalidate>- <h2>Sign in</h2>- <p class="hint">Password is <b>letmein</b>. Try a wrong value (or submit empty) to see the shake.</p>- <div class="field" id="field">- <label for="pw">Password</label>- <input type="password" id="pw" autocomplete="off" placeholder="••••••••">- <span class="msg" id="msg"></span>+<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="../cursor-follower/" rel="prev" aria-label="Previous: Cursor Follower"><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>Cursor Follower</span></a><a href="../swipe-to-dismiss/" rel="next" aria-label="Next: Swipe to Dismiss"><span><span class="hb-dir">Next: </span>Swipe to Dismiss</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.21 · Micro-Interactions</p>+ <h1>Error Shake</h1>+ <p class="hb-lede">A field shakes side to side when the input is wrong. Best for sign-in forms.</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>Sign in with a wrong or empty password (the right one is letmein), or press Show me.</p></div>+ </div>+ <div class="stage hb-dots">+ <form class="card" id="login" novalidate>+ <p class="card-title">Sign in</p>+ <div class="field" id="field">+ <label for="pw">Password</label>+ <input type="password" id="pw" autocomplete="off" placeholder="••••••••">+ <span class="msg" id="msg" aria-hidden="true"></span>+ </div>+ <button class="submit" type="submit">Sign in</button>+ <p class="sr-only" id="live" role="alert"></p>+ </form>+ </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="dist-lbl">Shake distance</p>+ <div class="seg" id="dist-seg" role="group" aria-labelledby="dist-lbl">+ <button type="button" data-x="4px" aria-pressed="false">Small</button>+ <button type="button" data-x="8px" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-x="14px" aria-pressed="false">Large</button>+ </div>+ <p class="hb-hint">How far the field swings left and right.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="swings-lbl">Number of swings</p>+ <div class="seg" id="swings-seg" role="group" aria-labelledby="swings-lbl">+ <button type="button" data-n="4" aria-pressed="false">Few</button>+ <button type="button" data-n="6" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-n="8" aria-pressed="false">Many</button>+ </div>+ <p class="hb-hint">Four to six swings read as a head 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="650" aria-pressed="false">Slow</button>+ <button type="button" data-ms="400" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="250" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How long the whole shake lasts.</p>+ </div>+ </div>+ </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 an error shake to [the form field that can be rejected, such as a password]. When the value is wrong or missing, move the field quickly left and right a few times, each swing smaller than the last, and end exactly where it started, like a head shaking no. Turn its border red and show a short message saying what went wrong, because movement and color alone do not explain the problem. Move only its horizontal position so the shake stays smooth, and restart the shake on every failed try. If the visitor has reduced motion turned on, skip the shake and keep the red border and the message. 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>- <button class="submit" type="submit">Sign in</button>- </form>- </div>- <aside>- <p class="note">A shake decays — big swings settle to small ones, then stop. That deceleration reads as a headshake: motion that returns to origin says "denied," not "progress."</p>- <div class="lbl">Shake intensity</div>- <div class="sr"><input type="range" id="int-sl" min="2" max="20" value="8" step="1"><span class="sval" id="int-v">8px</span></div>- <div class="lbl">Oscillations</div>- <div class="sr"><input type="range" id="osc-sl" min="2" max="8" value="6" step="1"><span class="sval" id="osc-v">6</span></div>- <div class="lbl">Duration</div>- <div class="sr"><input type="range" id="dur-sl" min="200" max="800" value="400" step="20"><span class="sval" id="dur-v">400ms</span></div>- <div class="div"></div>- <button class="replay" id="replay">↺ Replay shake</button>- </aside>-</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>Sign-in forms</li><li>Codes and PINs</li><li>Form fields</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Whole pages</li><li>Warnings</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 stage=document.querySelector('.stage');const form=document.getElementById('login');const field=document.getElementById('field');const input=document.getElementById('pw');const msg=document.getElementById('msg');+ const live=document.getElementById('live');const root=document.documentElement.style;const PASSWORD='letmein';+ const DEMO_PASSWORD='abc123'; // what Show me types in+ let dur=400; // the shake's length, which Show me waits for// Building the keyframe from the oscillation count keeps the demo honest:// more oscillations = more decaying swings written into one @keyframes.@@ -143,8 +202,20 @@ body{padding-top:46px}sheet.insertRule(`@keyframes shake{${steps}}`,sheet.cssRules.length);}- function clearState(){field.classList.remove('error','ok');}+ // Screen readers hear the result through the hidden alert; the message in the field is the same words for the eyes.+ // Only the visitor's own sign-in says anything: a Show me run stays silent.+ let sayTimer=0;+ function say(text){+ clearTimeout(sayTimer);+ live.textContent='';+ sayTimer=setTimeout(()=>{live.textContent=text},60);+ }+ function clearState(){+ field.classList.remove('error','ok');+ clearTimeout(sayTimer);live.textContent='';+ }+ // The visitor's failed sign-in and Show me both call thisfunction shake(text){clearState();// reflow forces the animation to restart even on repeated failures@@ -156,30 +227,72 @@ body{padding-top:46px}form.addEventListener('submit',e=>{e.preventDefault();const v=input.value.trim();- if(!v){shake('Password is required.');input.focus();return;}- if(v!==PASSWORD){shake('Incorrect password. Try again.');input.select();return;}- clearState();- msg.textContent='Welcome back — signed in.';- field.classList.add('ok');+ if(v===PASSWORD){+ clearState();+ msg.textContent='Welcome back — signed in.';+ field.classList.add('ok');+ }else{+ shake(v?'Incorrect password. Try again.':'Password is required.');+ if(v)input.select();else input.focus();+ }+ say(msg.textContent);});input.addEventListener('input',clearState);- document.getElementById('int-sl').addEventListener('input',e=>{- document.getElementById('int-v').textContent=e.target.value+'px';- root.setProperty('--shake-x',e.target.value+'px');- });- document.getElementById('osc-sl').addEventListener('input',e=>{- document.getElementById('osc-v').textContent=e.target.value;- buildShake(+e.target.value);- });- document.getElementById('dur-sl').addEventListener('input',e=>{- document.getElementById('dur-v').textContent=e.target.value+'ms';- root.setProperty('--shake-dur',e.target.value+'ms');+ // Show me: one run at a time. Every timer of the run goes through later(); stopRun() cancels the whole run.+ // later(fn, move, hold) waits move*(slow?3:1) + (hold||0) ms: Slow motion triples the movement, never the hold.+ const slowTog=document.getElementById('slow-tog'); // only on pages with Slow motion+ let runTimers=[];+ function later(fn,move,hold){+ const slow=!!(slowTog&&slowTog.checked);+ const id=setTimeout(()=>{ runTimers=runTimers.filter(t=>t!==id); fn(); }, move*(slow?3:1)+(hold||0));+ runTimers.push(id);+ }+ function running(){ return runTimers.length>0; }+ function stopRun(){ runTimers.forEach(clearTimeout); runTimers=[]; }+ function clearField(){input.value='';clearState()}+ // A run starts with an empty field and no error, put there without animating: the transitions are turned off, the field is+ // emptied, a reflow makes it stick, and the transitions come back.+ function toRest(){+ const parts=[input,msg];+ parts.forEach(p=>p.style.setProperty('transition','none','important'));+ clearField();+ void field.offsetWidth;+ 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',()=>{+ stopRun();+ toRest();+ input.value=DEMO_PASSWORD;+ later(()=>shake('Incorrect password. Try again.'),0,400);+ later(clearField,dur,2000);});- document.getElementById('replay').addEventListener('click',()=>shake('Incorrect password. Try again.'));+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops, and the run's password goes, so the+ // visitor starts from a clean field.+ function takeOver(){+ if(!running())return;+ stopRun();+ if(input.value===DEMO_PASSWORD)clearField();+ }+ document.addEventListener('hb:input',takeOver);+ // A Tab press from outside the stage sends no hb:input, but a run never moves the focus, so focus arriving in the stage while+ // one runs is the visitor's.+ stage.addEventListener('focusin',e=>{ if(e.isTrusted)takeOver(); });++ 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('dist-seg',d=>root.setProperty('--shake-x',d.x));+ choices('swings-seg',d=>buildShake(+d.n));+ choices('speed-seg',d=>{dur=+d.ms;root.setProperty('--shake-dur',d.ms+'ms')});buildShake(6);</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 a6e7d945..61e6d253 100644--- a/index.html+++ b/index.html@@ -971,7 +971,7 @@ const CATS=[['modal-expand','Modal Expand','A window grows out of the button you pressed. Best for detail views.'],['accordion','Accordion Open/Close','Each question opens smoothly to show its answer. Best for FAQ pages.'],['cursor-follower','Cursor Follower','A dot trails your pointer and flips the colors under it. Best for portfolios.'],- ['error-shake','Error Shake','An invalid field shakes horizontally with a decaying wobble and flashes red — the universal "no".'],+ ['error-shake','Error Shake','A field shakes side to side when the input is wrong. Best for sign-in forms.'],['swipe-to-dismiss','Swipe to Dismiss','Drag a card past a threshold and it flies off as the row collapses — pointer-driven, touch-ready.'],['hamburger-menu-toggle','Hamburger Menu Toggle','The bars icon morphs to an X — top and bottom bars rotate to cross while the middle fades out.'],['theme-toggle-morph','Theme Toggle Morph','A sun morphs into a crescent moon as the interface flips between light and dark.'],