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 Tooltip Reveal to the guided-steps page
matin87156a187130
diff --git a/animations/04-micro-interactions/tooltip-reveal/README.md b/animations/04-micro-interactions/tooltip-reveal/README.mdindex 6fc903a5..54d7c893 100644--- a/animations/04-micro-interactions/tooltip-reveal/README.md+++ b/animations/04-micro-interactions/tooltip-reveal/README.md@@ -1,7 +1,7 @@# Tooltip Reveal## What it is-A tooltip is a small floating label that appears near an element on hover (or focus), providing supplementary information that doesn't fit inline. The reveal animation — typically a fade combined with a subtle scale — makes the tooltip feel responsive rather than jarring. A delay before showing (300ms) prevents tooltips from triggering on accidental cursor pass-through.+A tooltip is a small label that appears next to an item when you point at it or reach it with the keyboard, giving a short explanation that does not fit on the page. It fades in and grows very slightly, and it waits a moment before it shows, so tooltips do not flash while the pointer is only passing over things. When the pointer leaves, it stays for a moment before it fades, so it does not vanish the instant the pointer slips off the item.## When to use it- Icon buttons without visible text labels@@ -10,7 +10,7 @@ A tooltip is a small floating label that appears near an element on hover (or fo- Data visualization elements (chart bars, graph nodes) that show exact values on hover## How it works-The tooltip is positioned absolutely relative to the trigger, initially invisible. On hover it fades and scales in after a `setTimeout` delay. On mouse-leave it hides after a short second delay — allowing the user to move the cursor from trigger to tooltip without it disappearing:+The tooltip is positioned absolutely relative to the trigger, initially invisible. On hover it fades and scales in after a `setTimeout` delay. On mouse-leave it hides after a short second delay, so it does not vanish the instant the pointer slips off the trigger:```css.tooltip {@@ -38,12 +38,12 @@ The tooltip is positioned absolutely relative to the trigger, initially invisibl```jslet showTimer, hideTimer;-trigger.addEventListener('mouseenter', () => {+trigger.addEventListener('pointerenter', () => {clearTimeout(hideTimer);showTimer = setTimeout(() => tip.classList.add('visible'), 300);});-trigger.addEventListener('mouseleave', () => {+trigger.addEventListener('pointerleave', () => {clearTimeout(showTimer);hideTimer = setTimeout(() => tip.classList.remove('visible'), 100);});@@ -59,24 +59,34 @@ trigger.addEventListener('focusout', () => {});```+Escape hides a shown tooltip at once, so it can be dismissed without moving the pointer or the focus:++```js+document.addEventListener('keydown', e => {+ if (e.key !== 'Escape') return;+ clearTimeout(showTimer);+ tip.classList.remove('visible');+});+```+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Show delay | 300ms | Prevents flash on cursor pass-through — the most important parameter |-| Hide delay | 100ms | Keeps tooltip alive briefly so the cursor can move onto it |-| Animation duration | 150ms | Fast enough to feel instant; slow enough to be perceivable |-| Scale start | 0.95 | Subtle — scale from 0.9 or less feels like a popup, not a tooltip |+| Delay before showing | Medium | How long the pointer must rest before the tooltip shows: none, short (150ms), medium (300ms) or long (600ms); 300ms keeps tooltips from flashing as the pointer passes, and 200ms can work for very small ones |+| Speed | Normal | How long the fade and the slight grow take: slow is 250ms, normal 150ms and fast 90ms |+| Delay before hiding | Short | How long the tooltip stays after the pointer leaves: none, short (100ms) or long (300ms); a short pause stops it vanishing the instant the pointer slips off its item |+| Shows an arrow | off | Adds a small point that aims the tooltip at its item |## Production notes- **The 300ms rule**: without a show delay, every cursor movement across the page triggers tooltip flashes. 300ms is the minimum that feels responsive without being annoying. 200ms can work if the tooltip is very small.- **Smart positioning**: the demo positions tooltips in fixed directions. Production implementations need viewport-aware positioning — flip the tooltip when it would overflow the edge. Floating UI (by Atomics Design) handles this automatically.- **Touch devices**: tooltips have no hover trigger on touch. Long-press or a dedicated info button is the touch equivalent. The demo uses `touchstart` to toggle visibility as a fallback.-- **`pointer-events: none`** on the tooltip prevents it from intercepting mouse events when using the `hide-delay` technique of allowing cursor movement onto the tooltip.-- **WCAG 1.4.13 (Content on Hover or Focus)**: the tooltip must be dismissible without moving the cursor (e.g., Escape key), hoverable itself without disappearing, and persistent until the cursor moves away. The 100ms hide delay satisfies "hoverable."+- **`pointer-events: none`** on the tooltip keeps it from catching the pointer, so it never blocks the item or its neighbors; the cost is that the pointer cannot rest on the tooltip itself, which the WCAG bullet covers.+- **WCAG 1.4.13 (Content on Hover or Focus)**: the tooltip must be dismissible without moving the cursor (e.g., Escape key), hoverable itself without disappearing, and persistent until the cursor moves away. The demo covers "dismissible": Escape hides a shown tooltip at once. A hide delay helps with "hoverable" only when the tooltip takes the pointer; the demo's tooltips have `pointer-events: none`, so a tooltip that must be hoverable needs pointer events on.- **Floating UI / Popper.js**: production-grade positioning library. `computePosition()` with `flip` and `shift` middleware handles all edge cases.- **Radix UI Tooltip**: `<Tooltip.Root>`, `<Tooltip.Trigger>`, `<Tooltip.Content>` — fully accessible, WCAG 1.4.13 compliant, animation-ready.## See also-- [Hover State Animation](../hover-state/) — hover feedback on the trigger element-- [Badge Pulse](../badge-pulse/) — persistent attention indicator vs. hover-triggered info-- [Modal Expand](../modal-expand/) — for content too large for a tooltip+- [Hover State Animation](../hover-state/) — items that react when the pointer is on them+- [Notification Badge Pulse](../badge-pulse/) — a dot that pulses to draw the eye+- [Modal Expand](../modal-expand/) — a full window for content too big for a tooltipdiff --git a/animations/04-micro-interactions/tooltip-reveal/index.html b/animations/04-micro-interactions/tooltip-reveal/index.htmlindex a787a3f5..aa9bf1ac 100644--- a/animations/04-micro-interactions/tooltip-reveal/index.html+++ b/animations/04-micro-interactions/tooltip-reveal/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Tooltip Reveal — Animation Handbook</title>- <meta name="description" content="Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.">+ <meta name="description" content="A small label fades in after a short pause. Best for icon buttons."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/tooltip-reveal/"><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="Tooltip Reveal — Animation Handbook">- <meta property="og:description" content="Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.">+ <meta property="og:description" content="A small label fades in after a short pause. Best for icon buttons."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/tooltip-reveal/"><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="Tooltip Reveal — Animation Handbook">- <meta name="twitter:description" content="Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.">+ <meta name="twitter:description" content="A small label fades in after a short pause. Best for icon buttons."><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": "Tooltip Reveal", "name": "Tooltip Reveal", "description": "Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/tooltip-reveal/", "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, Tooltip Reveal"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Tooltip Reveal", "name": "Tooltip Reveal", "description": "A small label fades in after a short pause. Best for icon buttons.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/tooltip-reveal/", "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, Tooltip Reveal"}</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;--tip-bg:#1c1c22;--stage-h:620px;--tip-dur:150ms;--show-delay:300ms;--hide-delay:100ms}+ :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-text:#f4f4f2;--ui-muted:#8a8a92;--tip-bg:#1c1c22;--tip-dur:150ms}*,*::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;flex-direction:column;align-items:center;justify-content:center;gap:28px;padding:32px}+ .stage{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:28px;padding:12px 16px;background:#0b0b0d}/* Tooltip base */.tip-wrap{position:relative;display:inline-flex}- .tooltip{position:absolute;background:var(--tip-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-size:11px;padding:7px 10px;border-radius:6px;white-space:nowrap;pointer-events:none;opacity:0;transform:scale(.95);transition:opacity var(--tip-dur) ease,transform var(--tip-dur) ease;z-index:10;width:max-content;max-width:200px;white-space:normal;line-height:1.5}+ .tooltip{position:absolute;background:var(--tip-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-size:11px;padding:7px 10px;border-radius:6px;pointer-events:none;opacity:0;transform:scale(.95);transition:opacity var(--tip-dur) ease,transform var(--tip-dur) ease;z-index:10;width:max-content;max-width:200px;line-height:1.5}.tooltip.visible{opacity:1;transform:scale(1)}/* Positions */.tip-top{bottom:calc(100% + 8px);left:50%;transform:translateX(-50%) scale(.95);transform-origin:bottom center}@@ -44,8 +35,6 @@.tip-bottom.visible{transform:translateX(-50%) scale(1)}.tip-right{left:calc(100% + 8px);top:50%;transform:translateY(-50%) scale(.95);transform-origin:left center}.tip-right.visible{transform:translateY(-50%) scale(1)}- .tip-left{right:calc(100% + 8px);top:50%;transform:translateY(-50%) scale(.95);transform-origin:right center}- .tip-left.visible{transform:translateY(-50%) scale(1)}/* Arrow */.has-arrow .tooltip::after{content:'';position:absolute;border:5px solid transparent}.has-arrow .tip-bottom::after{top:-10px;left:50%;transform:translateX(-50%);border-bottom-color:var(--tip-bg)}@@ -54,122 +43,234 @@/* Trigger elements */.icon-btn{width:52px;height:52px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:22px;cursor:pointer}.trunc-text{font-size:13px;max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer;padding:10px 12px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:6px;color:var(--ui-muted)}- .help-input{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:12px;padding:10px 12px;border-radius:6px;outline:none;min-height:44px;width:200px;transition:border-color .15s}+ .help-input{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:inherit;font-size:12px;padding:10px 12px;border-radius:6px;outline:none;min-height:44px;width:200px;transition:border-color .15s}+ .help-input::placeholder{color:var(--ui-muted);opacity:1}.help-input:focus{border-color:var(--ui-accent)}+ /* The field's own focus look (the border) replaces the site focus ring */+ .stage .help-input:focus-visible{outline:none}.avatar-sm{width:44px;height:44px;border-radius:50%;background:linear-gradient(135deg,#1a3060,#2a5090);display:flex;align-items:center;justify-content:center;font-size:18px;cursor:pointer;flex-shrink:0}- .row{display:flex;align-items:center;gap:12px}- /* 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)}- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}- .kv .v{color:var(--ui-text)}- .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:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}- @media(max-width:600px){- .layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:480px}.trunc-text{min-height:44px;line-height:24px}- /* No room to the right of the input on phones: flip the side tooltip below it */+ /* A stage 260px tall (a laptop window under about 600px, a phone held sideways) is shorter than the four items with their usual spacing */+ @media(min-width:601px) and (max-height:640px){.stage{gap:16px;padding:8px 16px}}+ /* Touch screens: the cut-off text is a tap target. Narrow screens: there is no room to the right of the field for its tooltip, so it opens below the field */+ @media(max-width:720px),(max-height:500px),(pointer:coarse){.trunc-text{min-height:44px;line-height:24px}}+ @media(max-width:720px){.tip-right{left:50%;right:auto;top:calc(100% + 8px);transform:translateX(-50%) scale(.95);transform-origin:top center}.tip-right.visible{transform:translateX(-50%) scale(1)}.has-arrow .tip-right::after{left:50%;top:-10px;transform:translateX(-50%);border-right-color:transparent;border-bottom-color:var(--tip-bg)}}+ /* At 16px a text field does not make iOS zoom in when it gets the focus */+ @media(pointer:coarse){.help-input{font-size:16px}}@media(prefers-reduced-motion:reduce){.tooltip{transition:opacity var(--tip-dur) ease!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="../badge-pulse/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../drawer-slide/" 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/tooltip-reveal/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Tooltip Reveal</h1>- <p>Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.</p>-</header>-<div class="layout">- <div class="stage">- <div class="tip-wrap" id="tw0">- <div class="icon-btn" tabindex="0" aria-describedby="tt0">⚙️</div>- <div class="tooltip tip-bottom" id="tt0" role="tooltip">Settings — configure your workspace preferences</div>- </div>- <div class="tip-wrap" id="tw1">- <div class="trunc-text" tabindex="0" aria-describedby="tt1">This text is truncat…</div>- <div class="tooltip tip-top" id="tt1" role="tooltip">This text is truncated because it is too long for the available space in this layout.</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="../badge-pulse/" rel="prev" aria-label="Previous: Notification Badge Pulse"><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>Notification Badge Pulse</span></a><a href="../drawer-slide/" rel="next" aria-label="Next: Drawer / Panel Slide"><span><span class="hb-dir">Next: </span>Drawer / Panel Slide</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.16 · Micro-Interactions</p>+ <h1>Tooltip Reveal</h1>+ <p class="hb-lede">A small label fades in after a short pause. Best for icon buttons.</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">Hover it</h2><p>Point at an item, tab to it or tap it on a phone, or press Show me.</p></div></div>- <div class="row">- <div class="tip-wrap" id="tw2" style="flex:1">- <input class="help-input" type="text" placeholder="Username" aria-describedby="tt2">+ <div class="stage hb-dots">+ <div class="tip-wrap" id="tw0">+ <div class="icon-btn" tabindex="0" aria-describedby="tt0">⚙️</div>+ <div class="tooltip tip-bottom" id="tt0" role="tooltip">Settings — configure your workspace preferences</div>+ </div>+ <div class="tip-wrap" id="tw1">+ <div class="trunc-text" tabindex="0" aria-describedby="tt1">This text is truncat…</div>+ <div class="tooltip tip-top" id="tt1" role="tooltip">This text is truncated because it is too long for the available space in this layout.</div>+ </div>+ <div class="tip-wrap" id="tw2">+ <input class="help-input" type="text" placeholder="Username" aria-label="Username" aria-describedby="tt2" autocomplete="off"><div class="tooltip tip-right" id="tt2" role="tooltip">3–20 characters. Letters, numbers and underscores only.</div></div>+ <div class="tip-wrap" id="tw3">+ <div class="avatar-sm" tabindex="0" aria-describedby="tt3">🧑</div>+ <div class="tooltip tip-top" id="tt3" role="tooltip">@atlas — joined 2019 · 140 projects</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="tip-wrap" id="tw3">- <div class="avatar-sm" tabindex="0" aria-describedby="tt3">🧑</div>- <div class="tooltip tip-top" id="tt3" role="tooltip">@atlas — joined 2019 · 140 projects</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="show-lbl">Delay before showing</p>+ <div class="seg" id="show-seg" role="group" aria-labelledby="show-lbl">+ <button type="button" data-ms="0" aria-pressed="false">None</button>+ <button type="button" data-ms="150" aria-pressed="false">Short</button>+ <button type="button" data-ms="300" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-ms="600" aria-pressed="false">Long</button>+ </div>+ <p class="hb-hint">The pause stops tips flashing as the pointer passes.</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="250" aria-pressed="false">Slow</button>+ <button type="button" data-ms="150" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="90" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How quickly the label fades and grows in.</p>+ </div></div>- </div>- <aside>- <p class="note">The 300ms show delay prevents triggering on accidental hover. Hide delay (100ms) lets users move from trigger to tooltip without losing it.</p>- <div class="lbl">Show Delay</div>- <div class="sr"><input type="range" id="show-sl" min="0" max="800" value="300" step="50"><span class="sv" id="show-v">300ms</span></div>- <div class="lbl">Hide Delay</div>- <div class="sr"><input type="range" id="hide-sl" min="0" max="500" value="100" step="25"><span class="sv" id="hide-v">100ms</span></div>- <div class="lbl">Duration</div>- <div class="sr"><input type="range" id="dur-sl" min="80" max="400" value="150" step="10"><span class="sv" id="dur-v">150ms</span></div>- <label class="tog" id="arrow-tog-wrap"><input type="checkbox" id="arrow-tog"><span>Show arrow</span></label>- <div class="div"></div>- <div class="kv"><span>Total shown</span><span class="v" id="total">0</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="hide-lbl">Delay before hiding</p>+ <div class="seg" id="hide-seg" role="group" aria-labelledby="hide-lbl">+ <button type="button" data-ms="0" aria-pressed="false">None</button>+ <button type="button" data-ms="100" class="on" aria-pressed="true">Short</button>+ <button type="button" data-ms="300" aria-pressed="false">Long</button>+ </div>+ <p class="hb-hint">How long the tip stays after the pointer leaves.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Shows an arrow</span><input class="hb-switch" type="checkbox" role="switch" id="arrow-tog" autocomplete="off"></label>+ <p class="hb-hint">A small point that aims the tip at its item.</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 tooltips to [the icon buttons, shortened text or fields that need a short explanation]. When the pointer rests on an item, or keyboard focus reaches it, wait a moment, then fade the tooltip in beside it while it grows very slightly from the side facing the item, so it feels light rather than like a pop-up. The wait keeps tooltips from flashing while the pointer only passes by. When the pointer leaves, hide it again, after a pause if the settings include one, and let the Escape key close it at once. On touch screens, show and hide it with a tap. If the visitor has reduced motion turned on, fade it without growing. 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>Icon buttons</li><li>Cut-off text</li><li>Form hints</li><li>Chart values</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Key information</li><li>Long text</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>- let showDelay=300,hideDelay=100,total=0;- const wraps=document.querySelectorAll('.tip-wrap');+ const stage=document.querySelector('.stage');+ const wraps=[...document.querySelectorAll('.tip-wrap')];+ const slowTog=document.getElementById('slow-tog');+ const canHover=window.matchMedia('(hover: hover)');+ const vars=document.documentElement.style;+ let showDelay=300,hideDelay=100,fadeMs=150,runTimers=[];+ // Each item shows and hides its own tooltip: the visitor's pointer, focus and tap and the Show me run all call the same two+ // functions. A delay of 0 shows or hides at once (a tap does), and dismiss() clears both timers and hides at once (Escape does).wraps.forEach(wrap=>{- const trigger=wrap.querySelector('[tabindex], input');const tip=wrap.querySelector('.tooltip');- let showTimer=null,hideTimer=null;-- function show(){+ let showTimer=0,hideTimer=0;+ function show(delay=showDelay){clearTimeout(hideTimer);clearTimeout(showTimer);- showTimer=setTimeout(()=>{tip.classList.add('visible');total++;document.getElementById('total').textContent=total;},showDelay);+ if(delay>0)showTimer=setTimeout(()=>tip.classList.add('visible'),delay);+ else tip.classList.add('visible');}- function hide(){- clearTimeout(showTimer);- hideTimer=setTimeout(()=>tip.classList.remove('visible'),hideDelay);+ function hide(delay=hideDelay){+ clearTimeout(showTimer);clearTimeout(hideTimer);+ if(delay>0)hideTimer=setTimeout(()=>tip.classList.remove('visible'),delay);+ else tip.classList.remove('visible');}-- wrap.addEventListener('mouseenter',show);- wrap.addEventListener('mouseleave',hide);- wrap.addEventListener('focusin',show);- wrap.addEventListener('focusout',hide);- // Touch fallback- wrap.addEventListener('touchstart',()=>{tip.classList.toggle('visible');},{passive:true});+ wrap.show=show;+ wrap.hide=hide;+ wrap.dismiss=()=>hide(0);+ // Hover only where a pointer can hover, and never for a finger: a tap shows the tooltip through touchstart below+ wrap.addEventListener('pointerenter',e=>{if(e.pointerType!=='touch'&&canHover.matches)show()});+ wrap.addEventListener('pointerleave',e=>{if(e.pointerType!=='touch'&&canHover.matches)hide()});+ wrap.addEventListener('focusin',()=>show());+ wrap.addEventListener('focusout',()=>hide());+ wrap.addEventListener('touchstart',()=>{if(tip.classList.contains('visible'))hide(0);else show(0)},{passive:true});});+ // Escape closes every shown tooltip at once; one comes back only when the pointer or the focus leaves its item and returns+ document.addEventListener('keydown',e=>{if(e.key==='Escape')wraps.forEach(w=>w.dismiss())});- document.getElementById('show-sl').addEventListener('input',e=>{showDelay=+e.target.value;document.getElementById('show-v').textContent=showDelay+'ms'});- document.getElementById('hide-sl').addEventListener('input',e=>{hideDelay=+e.target.value;document.getElementById('hide-v').textContent=hideDelay+'ms'});- document.getElementById('dur-sl').addEventListener('input',e=>{- document.getElementById('dur-v').textContent=e.target.value+'ms';- document.documentElement.style.setProperty('--tip-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 ms: Slow motion triples the movement, never the hold.+ function later(fn,move,hold){+ const id=setTimeout(()=>{runTimers=runTimers.filter(t=>t!==id);fn()},move*(slowTog.checked?3:1)+(hold||0));+ runTimers.push(id);+ }+ function running(){return runTimers.length>0}+ // A stopped run lets go of the gear's tooltip, unless the visitor's pointer or focus is on the gear+ function stopRun(){+ runTimers.forEach(clearTimeout);runTimers=[];+ if(!wraps[0].matches(':hover,:focus-within'))wraps[0].hide();+ }+ // A run starts with every tooltip hidden at once: the transitions are turned off, a reflow makes it stick, and they come back.+ function toRest(){+ const tips=[...stage.querySelectorAll('.tooltip')];+ tips.forEach(t=>t.style.setProperty('transition','none','important'));+ wraps.forEach(w=>w.dismiss());+ void stage.offsetWidth;+ tips.forEach(t=>t.style.removeProperty('transition'));+ }+ // One hover of the gear: its tooltip shows after the delay before showing, stays 1.6 s, then hides after the delay before hiding.+ // At the defaults it is back at rest 2.3 s after the press.+ document.getElementById('btn-demo').addEventListener('click',()=>{+ stopRun();+ toRest();+ wraps[0].show();+ later(()=>wraps[0].hide(),fadeMs,showDelay+1600);});+ // The visitor pressed, typed, scrolled or touched inside the stage, moved a pointer over it or tabbed into it: the run stops.+ document.addEventListener('hb:input',()=>{if(running())stopRun()});+ stage.addEventListener('pointermove',e=>{if(e.isTrusted&&running())stopRun()});+ 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);+ }));+ }+ choices('show-seg',d=>{showDelay=+d.ms});+ choices('speed-seg',d=>{fadeMs=+d.ms;vars.setProperty('--tip-dur',fadeMs+'ms')});+ choices('hide-seg',d=>{hideDelay=+d.ms});document.getElementById('arrow-tog').addEventListener('change',e=>{wraps.forEach(w=>w.classList.toggle('has-arrow',e.target.checked));});</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 c82f6a5a..425c678d 100644--- a/index.html+++ b/index.html@@ -966,7 +966,7 @@ const CATS=[['checkmark-draw','Checkmark Draw','A tick draws itself in a circle once a task succeeds. Best for forms.'],['form-field-morph','Form Field Morph','The label moves up out of the way as you type. Best for sign-up forms.'],['badge-pulse','Notification Badge Pulse','A badge on an icon pulses to catch the eye. Best for unread messages.'],- ['tooltip-reveal','Tooltip Reveal','Info box fades in after a 300ms delay — long enough to avoid triggering on mouse pass-through.'],+ ['tooltip-reveal','Tooltip Reveal','A small label fades in after a short pause. Best for icon buttons.'],['drawer-slide','Drawer / Panel Slide','Off-canvas panel slides from edge — ease-out open, ease-in close. Backdrop dismisses.'],['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.'],