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 Drawer / Panel Slide to the guided-steps page
matin6c1f817240ce
diff --git a/animations/04-micro-interactions/drawer-slide/README.md b/animations/04-micro-interactions/drawer-slide/README.mdindex 93852aa3..10700c1f 100644--- a/animations/04-micro-interactions/drawer-slide/README.md+++ b/animations/04-micro-interactions/drawer-slide/README.md@@ -1,7 +1,7 @@# Drawer / Panel Slide## What it is-A drawer is an off-canvas panel that slides in from a screen edge, typically carrying navigation, filters, or settings. It overlays the main content with a dimmed backdrop. The key animation insight is asymmetric easing: the drawer decelerates into its open position (ease-out — feels like arrival) and accelerates away when closing (ease-in — feels like dismissal).+A drawer is a panel that waits just beyond one edge of the screen and slides in over the page when you press its button, usually holding a menu, filters or settings. The page behind it usually dims so the drawer stands out. It slows down as it arrives, like a panel sliding to a stop, and speeds up as it leaves, which makes closing feel quicker than opening.## When to use it- Mobile navigation menus behind a hamburger button@@ -10,15 +10,16 @@ A drawer is an off-canvas panel that slides in from a screen edge, typically car- Context panels that appear alongside selected content (VS Code-style side panels)## How it works-The drawer starts translated fully off-screen and transitions to its natural position:+The drawer starts translated fully off-screen and transitions to its natural position. Its resting rule carries the closing speed and curve, and the open state carries the opening ones, so each direction has its own easing:```css:root {- --drawer-w: 280px;+ --drawer-w: min(280px, 80%);--open-dur: 280ms;--close-dur: 220ms;--open-ease: ease-out;--close-ease: ease-in;+ --backdrop-op: 0.5;}.drawer {@@ -26,35 +27,45 @@ The drawer starts translated fully off-screen and transitions to its natural postop: 0; left: 0; bottom: 0;width: var(--drawer-w);transform: translateX(-100%);- transition: transform var(--open-dur) var(--open-ease);+ transition: transform var(--close-dur) var(--close-ease);will-change: transform;z-index: 200;}.drawer.open {transform: translateX(0);+ transition: transform var(--open-dur) var(--open-ease);}/* Backdrop */.backdrop {position: fixed; inset: 0;- background: rgba(0,0,0,.5);+ background: rgba(0,0,0,var(--backdrop-op));opacity: 0;- transition: opacity var(--open-dur) ease;+ transition: opacity var(--close-dur) var(--close-ease);pointer-events: none;z-index: 199;}.backdrop.visible {opacity: 1;pointer-events: auto;+ transition: opacity var(--open-dur) var(--open-ease);}```Close on Escape key, backdrop click, and swipe gesture:```js-function open() { drawer.classList.add('open'); backdrop.classList.add('visible'); }-function close() { drawer.classList.remove('open'); backdrop.classList.remove('visible'); }+function open() {+ drawer.classList.add('open');+ backdrop.classList.add('visible');+ drawer.inert = false;+}+function close() {+ drawer.classList.remove('open');+ backdrop.classList.remove('visible');+ drawer.inert = true; // a closed drawer cannot be reached with Tab+}document.addEventListener('keydown', e => { if (e.key === 'Escape') close(); });backdrop.addEventListener('click', close);@@ -68,11 +79,10 @@ drawer.addEventListener('pointerup', e => { if (e.clientX - dragStartX < -50)## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Open duration | 280ms | 200–350ms — the drawer must feel instant, not cinematic |-| Close duration | 220ms | Slightly shorter than open — dismissal feels snappier than arrival |-| Open easing | ease-out | Decelerates into position — mimics a physical panel sliding to a stop |-| Close easing | ease-in | Accelerates away — mimics a panel being pulled |-| Backdrop opacity | 0.5 | 0.3–0.6 range; above 0.7 feels like a modal, not a drawer |+| Slides in from | Left | The edge the drawer comes from: left or right for menus and filters, top or bottom for sheets |+| Opening speed | Normal | How long the slide in takes: slow is 450ms, normal 280ms and fast 170ms; it slows as it arrives |+| Closing speed | Normal | How long the slide out takes: slow is 350ms, normal 220ms and fast 130ms; it speeds up as it leaves, and a little shorter than opening feels right |+| Page dimming | Medium | How dark the page behind gets: none, light (25% black), medium (50%) or dark (70%); darker than about 70% feels like a dialog rather than a drawer |## Production notes- **Focus trap**: when the drawer is open, Tab focus must cycle within it. Use a focus trap library (e.g., `focus-trap`) or the native `<dialog>` element which traps focus automatically.@@ -83,6 +93,6 @@ drawer.addEventListener('pointerup', e => { if (e.clientX - dragStartX < -50)- **Radix UI Sheet / shadcn Drawer**: fully accessible, animated drawer components. Vaul (Emil Kowalski) adds native mobile-style drag-to-dismiss for bottom drawers.## See also-- [Modal Expand](../modal-expand/) — for content that should appear centered, not from an edge-- [Accordion Open/Close](../accordion/) — inline expand/collapse rather than overlay-- [Tooltip Reveal](../tooltip-reveal/) — lightweight alternative for small amounts of additional information+- [Modal Expand](../modal-expand/) — a window that grows out of the button you pressed+- [Accordion Open/Close](../accordion/) — sections that open in place instead of over the page+- [Tooltip Reveal](../tooltip-reveal/) — a small label for a short explanationdiff --git a/animations/04-micro-interactions/drawer-slide/index.html b/animations/04-micro-interactions/drawer-slide/index.htmlindex b5d6be10..dac22d02 100644--- a/animations/04-micro-interactions/drawer-slide/index.html+++ b/animations/04-micro-interactions/drawer-slide/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Drawer / Panel Slide — Animation Handbook</title>- <meta name="description" content="Off-canvas panel slides from edge — ease-out open, ease-in close. Swipe or backdrop to dismiss.">+ <meta name="description" content="A side panel slides in over a dimmed page. Best for mobile menus."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/drawer-slide/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,30 +12,21 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Drawer / Panel Slide — Animation Handbook">- <meta property="og:description" content="Off-canvas panel slides from edge — ease-out open, ease-in close. Swipe or backdrop to dismiss.">+ <meta property="og:description" content="A side panel slides in over a dimmed page. Best for mobile menus."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/drawer-slide/"><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="Drawer / Panel Slide — Animation Handbook">- <meta name="twitter:description" content="Off-canvas panel slides from edge — ease-out open, ease-in close. Swipe or backdrop to dismiss.">+ <meta name="twitter:description" content="A side panel slides in over a dimmed page. Best for mobile menus."><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": "Drawer / Panel Slide", "name": "Drawer / Panel Slide", "description": "Off-canvas panel slides from edge — ease-out open, ease-in close. Swipe or backdrop to dismiss.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/drawer-slide/", "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, Drawer / Panel Slide"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Drawer / Panel Slide", "name": "Drawer / Panel Slide", "description": "A side panel slides in over a dimmed page. Best for mobile menus.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/drawer-slide/", "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, Drawer / Panel Slide"}</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;--drawer-w:280px;--open-dur:280ms;--close-dur:220ms;--open-ease:ease-out;--close-ease:ease-in;--backdrop-op:0.5}+ :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-text:#f4f4f2;--ui-muted:#8a8a92;--drawer-w:min(280px,80%);--open-dur:280ms;--close-dur:220ms;--open-ease:ease-out;--close-ease:ease-in;--backdrop-op:0.5}*,*::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);overflow:hidden;position:relative;display:flex;flex-direction:column}+ .stage{position:relative;overflow:hidden;display:flex;flex-direction:column;background:#0b0b0d}/* App header */.app-header{display:flex;align-items:center;gap:12px;padding:14px 16px;border-bottom:1px solid var(--ui-border);background:var(--ui-bg);flex-shrink:0}- .hamburger{background:none;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:16px;width:44px;height:44px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:border-color .15s;flex-shrink:0}+ .hamburger{background:none;border:1px solid var(--ui-border);color:var(--ui-text);font-family:inherit;font-size:16px;width:44px;height:44px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:border-color .15s;flex-shrink:0}@media(hover:hover){.hamburger:hover{border-color:var(--ui-accent)}}.app-title{font-size:13px;font-weight:bold;letter-spacing:1px}/* App body */@@ -53,111 +44,192 @@.drawer.open{transform:translate(0,0);transition:transform var(--open-dur) var(--open-ease)}.drawer-header{display:flex;align-items:center;justify-content:space-between;padding:16px;border-bottom:1px solid var(--ui-border);flex-shrink:0}.drawer-title{font-size:12px;font-weight:bold;text-transform:uppercase;letter-spacing:1px}- .close-btn{background:none;border:none;color:var(--ui-muted);font-size:18px;cursor:pointer;width:44px;height:44px;display:flex;align-items:center;justify-content:center;border-radius:4px}+ .close-btn{background:none;border:none;color:var(--ui-muted);font-family:inherit;font-size:18px;cursor:pointer;width:44px;height:44px;display:flex;align-items:center;justify-content:center;border-radius:4px}@media(hover:hover){.close-btn:hover{color:var(--ui-text)}}- .drawer-body{padding:16px;display:flex;flex-direction:column;gap:4px;flex:1;overflow-y:auto}+ .drawer-body{padding:12px;display:flex;flex-direction:column;gap:4px;flex:1;overflow-y:auto;touch-action:pan-y}.nav-item{padding:10px 12px;border-radius:6px;font-size:12px;cursor:pointer;transition:background .15s;min-height:44px;display:flex;align-items:center}@media(hover:hover){.nav-item:hover{background:rgba(255,255,255,.05)}}.nav-item.active{color:var(--ui-accent)}- /* Panel */- 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)}- .div{height:1px;background:var(--ui-border)}- .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}- .sv{width:44px;text-align:right;color:var(--ui-text)}- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}- .kv .v{color:var(--ui-text)}- @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}+ /* A window this short gives the stage 260px, less than the four menu items need: the drawer gives up some spacing, the items keep their size */+ @media(min-width:601px) and (max-height:620px){.drawer-header{padding:8px 16px}.drawer-body{padding:8px 12px;gap:0}}@media(prefers-reduced-motion:reduce){.drawer,.backdrop{transition: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="../tooltip-reveal/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../modal-expand/" 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/drawer-slide/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Drawer / Panel Slide</h1>- <p>Off-canvas panel slides from edge — ease-out open, ease-in close. Swipe or backdrop to dismiss.</p>-</header>-<div class="layout">- <div class="stage" id="stage">- <div class="app-header">- <button class="hamburger" id="open-btn" aria-label="Open menu" aria-expanded="false" aria-controls="drawer">☰</button>- <div class="app-title">Atlas App</div>+<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="../tooltip-reveal/" rel="prev" aria-label="Previous: Tooltip Reveal"><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>Tooltip Reveal</span></a><a href="../modal-expand/" rel="next" aria-label="Next: Modal Expand"><span><span class="hb-dir">Next: </span>Modal Expand</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.17 · Micro-Interactions</p>+ <h1>Drawer / Panel Slide</h1>+ <p class="hb-lede">A side panel slides in over a dimmed page. Best for mobile menus.</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>Press the menu button, then close the drawer with × or a swipe, or press Show me.</p></div>+ </div>+ <div class="stage">+ <div class="app-header">+ <button class="hamburger" id="open-btn" type="button" aria-label="Open menu" aria-expanded="false" aria-controls="drawer">☰</button>+ <div class="app-title">Atlas App</div>+ </div>+ <div class="app-body">+ <div class="content-line w100"></div><div class="content-line w80"></div>+ <div class="content-line w60"></div><div class="content-line w100"></div>+ <div class="content-line w40"></div><div class="content-line w80"></div>+ </div>+ <div class="backdrop" id="backdrop" aria-hidden="true"></div>+ <div class="drawer" id="drawer" role="dialog" aria-modal="true" aria-label="Navigation menu" tabindex="-1" inert>+ <div class="drawer-header">+ <div class="drawer-title">Menu</div>+ <button class="close-btn" id="close-btn" type="button" aria-label="Close menu">×</button>+ </div>+ <div class="drawer-body">+ <div class="nav-item active">Home</div>+ <div class="nav-item">Gallery</div>+ <div class="nav-item">About</div>+ <div class="nav-item">Contact</div>+ </div>+ </div>+ </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>- <div class="app-body">- <div class="content-line w100"></div><div class="content-line w80"></div>- <div class="content-line w60"></div><div class="content-line w100"></div>- <div class="content-line w40"></div><div class="content-line w80"></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="backdrop" id="backdrop" aria-hidden="true"></div>- <div class="drawer" id="drawer" role="dialog" aria-modal="true" aria-label="Navigation menu">- <div class="drawer-header">- <div class="drawer-title">Menu</div>- <button class="close-btn" id="close-btn" aria-label="Close menu">×</button>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="side-lbl">Slides in from</p>+ <div class="seg" id="side-seg" role="group" aria-labelledby="side-lbl">+ <button type="button" data-side="left" class="on" aria-pressed="true">Left</button>+ <button type="button" data-side="right" aria-pressed="false">Right</button>+ <button type="button" data-side="top" aria-pressed="false">Top</button>+ <button type="button" data-side="bottom" aria-pressed="false">Bottom</button>+ </div>+ <p class="hb-hint">The edge the drawer comes in from.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="open-lbl">Opening speed</p>+ <div class="seg" id="open-seg" role="group" aria-labelledby="open-lbl">+ <button type="button" data-ms="450" aria-pressed="false">Slow</button>+ <button type="button" data-ms="280" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="170" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">It slows down as it arrives, like a panel landing.</p></div>- <div class="drawer-body">- <div class="nav-item active">Home</div>- <div class="nav-item">Gallery</div>- <div class="nav-item">About</div>- <div class="nav-item">Contact</div>- <div class="nav-item" style="margin-top:auto;color:var(--ui-muted)">Settings</div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="close-lbl">Closing speed</p>+ <div class="seg" id="close-seg" role="group" aria-labelledby="close-lbl">+ <button type="button" data-ms="350" aria-pressed="false">Slow</button>+ <button type="button" data-ms="220" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="130" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">It speeds up as it leaves, so closing feels quick.</p></div></div>- </div>- <aside>- <p class="note">Asymmetric easing: ease-out on open (decelerates into position — feels like arrival), ease-in on close (accelerates away — feels like dismissal).</p>- <div class="lbl">Drawer Side</div>- <select id="side-sel">- <option value="left" selected>Left</option>- <option value="right">Right</option>- <option value="top">Top</option>- <option value="bottom">Bottom</option>- </select>- <div class="lbl">Open Duration</div>- <div class="sr"><input type="range" id="odur-sl" min="100" max="500" value="280" step="20"><span class="sv" id="odur-v">280ms</span></div>- <div class="lbl">Close Duration</div>- <div class="sr"><input type="range" id="cdur-sl" min="80" max="400" value="220" step="20"><span class="sv" id="cdur-v">220ms</span></div>- <div class="lbl">Backdrop Opacity</div>- <div class="sr"><input type="range" id="bop-sl" min="0" max="70" value="50" step="5"><span class="sv" id="bop-v">0.50</span></div>- <div class="div"></div>- <div class="kv"><span>State</span><span class="v" id="state-v">Closed</span></div>- </aside>-</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="dim-lbl">Page dimming</p>+ <div class="seg" id="dim-seg" role="group" aria-labelledby="dim-lbl">+ <button type="button" data-op="0" aria-pressed="false">None</button>+ <button type="button" data-op="0.25" aria-pressed="false">Light</button>+ <button type="button" data-op="0.5" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-op="0.7" aria-pressed="false">Dark</button>+ </div>+ <p class="hb-hint">How dark the page behind the drawer gets.</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 a slide-in drawer to [the menu or panel you want to open]. It waits just beyond one edge of the screen and slides in over the page when its button is pressed; when the settings include it, the page behind it dims. Let it slow down as it arrives, like a panel sliding to a stop, and speed up as it leaves, so closing feels quicker than opening. Close it with a close button, a tap on the page beside it, the Escape key or a swipe back toward its edge. Move only its position, and keep keyboard focus inside it while it is open. If the visitor has reduced motion turned on, show and hide it without sliding. 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>Mobile menus</li><li>Filters</li><li>Settings panels</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Short messages</li><li>Main content</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 drawer=document.getElementById('drawer');const backdrop=document.getElementById('backdrop');const openBtn=document.getElementById('open-btn');- const stateEl=document.getElementById('state-v');- let isOpen=false,side='left',dragging=false,dragStartX=0,dragStartY=0;+ const closeBtn=document.getElementById('close-btn');+ const vars=document.documentElement.style;+ let isOpen=false,side='left',dragging=false,dragStartX=0,dragStartY=0,openDur=280;function open(){+ drawer.inert=false;drawer.classList.add('open');backdrop.classList.add('visible');- openBtn.setAttribute('aria-expanded','true');isOpen=true;stateEl.textContent='Open';+ openBtn.setAttribute('aria-expanded','true');isOpen=true;}function close(){drawer.classList.remove('open');backdrop.classList.remove('visible');- openBtn.setAttribute('aria-expanded','false');isOpen=false;stateEl.textContent='Closed';+ openBtn.setAttribute('aria-expanded','false');isOpen=false;+ drawer.inert=true; // a closed drawer cannot be reached with Tab}-- openBtn.addEventListener('click',open);- document.getElementById('close-btn').addEventListener('click',close);- backdrop.addEventListener('click',close);- document.addEventListener('keydown',e=>{if(e.key==='Escape'&&isOpen)close()});+ // The visitor's own way in and out. Keyboard focus goes into the drawer when it opens and back to the menu button when it+ // closes, unless the visitor has moved on to another control in the meantime. Show me calls open() and close() alone: a run+ // never moves the focus.+ function dismiss(){+ const a=document.activeElement,mine=a===document.body||drawer.contains(a);+ close();+ if(mine)openBtn.focus({preventScroll:true});+ }+ openBtn.addEventListener('click',()=>{open();closeBtn.focus({preventScroll:true})});+ closeBtn.addEventListener('click',dismiss);+ backdrop.addEventListener('click',dismiss);+ document.addEventListener('keydown',e=>{if(e.key==='Escape'&&isOpen)dismiss()});+ // Tab stays inside the open drawer: past its last control it goes back to the first, and Shift+Tab goes the other way.+ drawer.addEventListener('keydown',e=>{+ if(e.key!=='Tab')return;+ const f=[...drawer.querySelectorAll('button')],i=f.indexOf(document.activeElement);+ e.preventDefault();+ f[e.shiftKey?(i<=0?f.length-1:i-1):(i<0||i===f.length-1?0:i+1)].focus({preventScroll:true});+ });// Swipe to closedrawer.addEventListener('pointerdown',e=>{dragging=true;dragStartX=e.clientX;dragStartY=e.clientY});@@ -165,35 +237,62 @@ body{padding-top:46px}document.addEventListener('pointerup',e=>{if(!dragging)return;dragging=false;const dx=e.clientX-dragStartX,dy=e.clientY-dragStartY;- if(side==='left'&&dx<-50)close();- if(side==='right'&&dx>50)close();- if(side==='top'&&dy<-50)close();- if(side==='bottom'&&dy>50)close();+ if(side==='left'&&dx<-50||side==='right'&&dx>50||side==='top'&&dy<-50||side==='bottom'&&dy>50)dismiss();});- document.getElementById('side-sel').addEventListener('change',e=>{+ // 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=[]; }+ // A run starts with the drawer closed, put there without animating: the transitions are turned off, the drawer is closed,+ // a reflow makes it stick, and the transitions come back.+ function toRest(){+ const parts=[drawer,backdrop];+ parts.forEach(p=>p.style.setProperty('transition','none','important'));+ close();+ void drawer.offsetWidth;+ parts.forEach(p=>p.style.removeProperty('transition'));+ }+ // The drawer opens as the menu button opens it, waits 1.5 s, and closes (the slide in is the movement the wait counts).+ document.getElementById('btn-demo').addEventListener('click',()=>{+ stopRun();+ toRest();+ open();+ later(close,openDur,1500);+ });+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops and the drawer stays as it is.+ document.addEventListener('hb:input',()=>{ if(running()) stopRun(); });+ // A Tab press from outside the stage sends no hb:input (the key goes to the control that had the focus), but a run never+ // moves the focus, so focus arriving in the stage while one runs is the visitor's: the drawer must not close under it.+ document.querySelector('.stage').addEventListener('focusin',e=>{ if(e.isTrusted&&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);+ }));+ }+ // An open drawer closes first; the class then changes without a transition, so it never slides across the stage+ choices('side-seg',d=>{if(isOpen)close();- side=e.target.value;+ side=d.side;drawer.style.transition='none';drawer.className='drawer';if(side!=='left')drawer.classList.add(side);void drawer.offsetWidth;drawer.style.transition='';});- document.getElementById('odur-sl').addEventListener('input',e=>{- document.getElementById('odur-v').textContent=e.target.value+'ms';- document.documentElement.style.setProperty('--open-dur',e.target.value+'ms');- });- document.getElementById('cdur-sl').addEventListener('input',e=>{- document.getElementById('cdur-v').textContent=e.target.value+'ms';- document.documentElement.style.setProperty('--close-dur',e.target.value+'ms');- });- document.getElementById('bop-sl').addEventListener('input',e=>{- const v=(e.target.value/100).toFixed(2);- document.getElementById('bop-v').textContent=v;- document.documentElement.style.setProperty('--backdrop-op',v);- });+ choices('open-seg',d=>{openDur=+d.ms;vars.setProperty('--open-dur',d.ms+'ms')});+ choices('close-seg',d=>{vars.setProperty('--close-dur',d.ms+'ms')});+ choices('dim-seg',d=>{vars.setProperty('--backdrop-op',d.op)});</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 b19b7d62..ab99bd73 100644--- a/index.html+++ b/index.html@@ -967,7 +967,7 @@ const CATS=[['form-field-morph','Form Field Morph','Floating label rises out of the input on focus — persists when the field is filled.'],['badge-pulse','Notification Badge Pulse','Dot on icon pulses to draw peripheral attention — scale, halo, or both.'],['tooltip-reveal','Tooltip Reveal','Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.'],- ['drawer-slide','Drawer / Panel Slide','Off-canvas panel slides from edge — ease-out open, ease-in close. Backdrop dismisses.'],+ ['drawer-slide','Drawer / Panel Slide','A side panel slides in over a dimmed page. Best for mobile menus.'],['modal-expand','Modal Expand','Modal scales from the trigger button\'s position — transform-origin set to where you clicked.'],['accordion','Accordion Open/Close','Height animates between 0 and auto — JS measured height vs CSS grid-template-rows compared.'],['cursor-follower','Cursor Follower','Custom element follows mouse with lerp lag — mix-blend-mode: difference inverts any background.'],