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 Grid / Dot Pattern Parallax to the guided-steps page
matin775a892f3699
diff --git a/animations/07-ambient-background/grid-dot-pattern-parallax/README.md b/animations/07-ambient-background/grid-dot-pattern-parallax/README.mdindex 7dbd76cc..1bffcf36 100644--- a/animations/07-ambient-background/grid-dot-pattern-parallax/README.md+++ b/animations/07-ambient-background/grid-dot-pattern-parallax/README.md@@ -1,7 +1,7 @@# Grid / Dot Pattern Parallax## What it is-A grid or dot pattern parallax translates a subtle background pattern slightly in the opposite direction of the mouse cursor, creating a faint sense of depth between the pattern layer and the foreground content. The displacement is deliberately small — 3–8% of the cursor's position — so the effect is felt more than seen. This is the subtlest ambient effect in this category and one of the most professionally used: Linear's marketing site, Vercel's dashboard, and many developer-tool landing pages use this pattern.+A grid or dot pattern parallax places a faint repeating pattern of dots or lines behind the content and shifts it slightly in the opposite direction to the pointer. The shift is tiny, a few percent of the pointer's movement, so the pattern seems to sit a little deeper than the content: depth you feel more than see. When no pointer is over it, the grid drifts slowly by itself. Linear, Vercel and many developer tools use it.## When to use it- Technical and developer-tool landing pages where grid patterns signal "structured and precise"@@ -13,7 +13,7 @@ A grid or dot pattern parallax translates a subtle background pattern slightly iThe pattern is created using CSS `background-image` with a radial or linear gradient that tiles. The pattern layer is slightly larger than the container (10% overflow on each side) to provide drift headroom. Mouse position is tracked and mapped to a translation offset:```js-stage.addEventListener('mousemove', e => {+stage.addEventListener('pointermove', e => {const rect = stage.getBoundingClientRect();const normX = (e.clientX - rect.left) / rect.width - 0.5; // -0.5 to 0.5const normY = (e.clientY - rect.top) / rect.height - 0.5;@@ -26,6 +26,8 @@ stage.addEventListener('mousemove', e => {});```+Pointer events cover a mouse, a pen and a finger. The demo's stage has `touch-action: pan-y`, so a sideways drag steers the grid while a vertical swipe still scrolls the page, and only a mouse turns on the cursor ring and the light.+**CSS dot grid** using radial gradient:```css@@ -44,18 +46,21 @@ stage.addEventListener('mousemove', e => {```css.line-grid {background-image:- linear-gradient(rgba(88, 166, 255, 0.15) 1px, transparent 1px),- linear-gradient(90deg, rgba(88, 166, 255, 0.15) 1px, transparent 1px);+ linear-gradient(rgba(88, 166, 255, 0.25) 1px, transparent 1px),+ linear-gradient(90deg, rgba(88, 166, 255, 0.25) 1px, transparent 1px);background-size: 28px 28px;}```-**Auto-drift fallback** for touch devices (no mouse hover):+**Auto-drift** when no pointer is over the stage (and on touch screens between drags):```js-function autoLoop(t) {- const dx = -Math.sin(t * 0.0002) * STRENGTH * W * 0.4;- const dy = -Math.cos(t * 0.00014) * STRENGTH * H * 0.3;+let clock = 0, last = null;+function autoLoop(now) {+ clock += last === null ? 0 : Math.min(now - last, 50); // the drift's own clock stops while paused+ last = now;+ const dx = -Math.sin(clock * 0.0002) * STRENGTH * W * 0.4;+ const dy = -Math.cos(clock * 0.00014) * STRENGTH * H * 0.3;patternLayer.style.transform = `translate(${dx}px, ${dy}px)`;requestAnimationFrame(autoLoop);}@@ -64,10 +69,12 @@ function autoLoop(t) {## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Parallax strength | 5% | Under 3% = unnoticeable; 5% = felt but not seen; above 10% = visually obvious |-| Dot spacing | 28px | 16px = dense technical; 28px = balanced; 48px = sparse, airy |-| Pattern opacity | 25% | Higher = more prominent pattern; lower = nearly invisible texture |-| Two-layer | Off | Second sparse layer at half the speed adds genuine depth between layers |+| Pattern | Dots | A grid of dots, of lines, or both |+| Strength | Medium | How far the grid shifts: subtle is 3% of the pointer's movement, medium 5% and strong 10%; under 10% it is felt more than seen |+| Spacing | Medium | The distance between dots or lines: tight is 20px, medium 28px and wide 44px |+| Pattern color | Blue | The color of the dots and lines, shown at 25% so they stay faint |+| Second layer | off | A sparser layer of larger dots shifts half as far, adding real depth between the two |+| Light under the pointer | on | A faint round glow follows the pointer |## Production notes- **`background-size` controls spacing, not dot size**: the dot size is the gradient stop value (e.g., `1.5px`). The `background-size` is the tile repeat interval.@@ -77,6 +84,6 @@ function autoLoop(t) {- **SVG pattern alternative**: `<svg><pattern>` can define more complex repeating patterns (hexagons, triangles, etc.) as background images via `background-image: url("data:image/svg+xml,...")`. This keeps the pattern as pure CSS/SVG with no canvas overhead.## See also-- [Floating Elements](../floating-elements/) — moving shapes rather than a static pattern with parallax-- [2.5D / Pseudo-3D](../../06-3d-advanced/2-5d-pseudo-3d/) — multiple layers at genuinely different depths-- [Parallax 3D Tilt](../../06-3d-advanced/parallax-3d-tilt/) — mouse-driven 3D rotation on cards+- [Floating Elements](../floating-elements/) — shapes that drift on their own instead+- [2.5D / Pseudo-3D](../../06-3d-advanced/2-5d-pseudo-3d/) — many layers moving at different depths+- [Parallax 3D Tilt](../../06-3d-advanced/parallax-3d-tilt/) — a card that tilts toward the pointerdiff --git a/animations/07-ambient-background/grid-dot-pattern-parallax/index.html b/animations/07-ambient-background/grid-dot-pattern-parallax/index.htmlindex 8fc18602..bdbe6138 100644--- a/animations/07-ambient-background/grid-dot-pattern-parallax/index.html+++ b/animations/07-ambient-background/grid-dot-pattern-parallax/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Grid / Dot Pattern Parallax — Animation Handbook</title>- <meta name="description" content="Subtle background pattern translates opposite to mouse movement — imperceptible depth, very effective.">+ <meta name="description" content="A dot grid shifts gently against your pointer for depth. Best for tech sites."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/grid-dot-pattern-parallax/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,29 +12,21 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Grid / Dot Pattern Parallax — Animation Handbook">- <meta property="og:description" content="Subtle background pattern translates opposite to mouse movement — imperceptible depth, very effective.">+ <meta property="og:description" content="A dot grid shifts gently against your pointer for depth. Best for tech sites."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/grid-dot-pattern-parallax/"><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="Grid / Dot Pattern Parallax — Animation Handbook">- <meta name="twitter:description" content="Subtle background pattern translates opposite to mouse movement — imperceptible depth, very effective.">+ <meta name="twitter:description" content="A dot grid shifts gently against your pointer for depth. Best for tech sites."><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": "Grid / Dot Pattern Parallax", "name": "Grid / Dot Pattern Parallax", "description": "Subtle background pattern translates opposite to mouse movement — imperceptible depth, very effective.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/grid-dot-pattern-parallax/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Grid / Dot Pattern Parallax"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Grid / Dot Pattern Parallax", "name": "Grid / Dot Pattern Parallax", "description": "A dot grid shifts gently against your pointer for depth. Best for tech sites.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/grid-dot-pattern-parallax/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Grid / Dot Pattern Parallax"}</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:#ffce5a;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--dot-color:rgba(88,166,255,.25);--bg-color:#04060c;--dot-size:1.5px;--dot-gap:28px}+ :root{--ui-accent:#ffce5a;--dot-color:rgba(88,166,255,.25);--dot-size:1.5px;--dot-gap:28px}*,*::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;overflow:hidden;position:relative;background:var(--bg-color);cursor:none}+ /* cursor:none because the ring below replaces the pointer; pan-y lets a sideways drag steer the grid while a vertical swipe still scrolls the page */+ .stage{position:relative;overflow:hidden;background:#04060c;cursor:none;touch-action:pan-y}/* Pattern layer */- .pattern-layer{position:absolute;inset:-10%;transition:transform 0ms linear;will-change:transform}+ .pattern-layer{position:absolute;inset:-10%;will-change:transform}.pat-dots{width:100%;height:100%;background-image:radial-gradient(circle,var(--dot-color) var(--dot-size),transparent 0);@@ -55,160 +47,273 @@background-size:var(--dot-gap) var(--dot-gap);display:none}- /* Spotlight on hover */- .spotlight{position:absolute;width:180px;height:180px;border-radius:50%;background:radial-gradient(circle,rgba(88,166,255,.06) 0%,transparent 70%);pointer-events:none;transform:translate(-50%,-50%);opacity:0;transition:opacity .2s;z-index:4}- /* Custom cursor */- .cursor{position:absolute;width:12px;height:12px;border-radius:50%;border:1.5px solid rgba(88,166,255,.5);pointer-events:none;transform:translate(-50%,-50%);z-index:10;display:none}- /* Auto-drift animation */- .auto-drift{animation:auto-pan 20s ease-in-out infinite alternate}- @keyframes auto-pan{0%{transform:translate(0,0)}50%{transform:translate(-3%,-2%)}100%{transform:translate(3%,2%)}}+ /* Light under the pointer and the ring that replaces it: both are placed with transform */+ .spotlight{position:absolute;left:0;top:0;width:180px;height:180px;border-radius:50%;background:radial-gradient(circle,rgba(88,166,255,.06) 0%,transparent 70%);pointer-events:none;transform:translate(-50%,-50%);opacity:0;transition:opacity .2s;z-index:4}+ .cursor{position:absolute;left:0;top:0;width:12px;height:12px;border-radius:50%;border:1.5px solid rgba(88,166,255,.5);pointer-events:none;transform:translate(-50%,-50%);z-index:10;display:none}/* Layer 2 (sparse) */- .pattern-layer2{position:absolute;inset:-10%;opacity:.4;display:none;transition:transform 0ms linear;will-change:transform}+ .pattern-layer2{position:absolute;inset:-10%;opacity:.4;display:none;will-change:transform}.pat-layer2{width:100%;height:100%;background-image:radial-gradient(circle,var(--dot-color) calc(var(--dot-size)*1.5),transparent 0);background-size:calc(var(--dot-gap)*2.5) calc(var(--dot-gap)*2.5)}/* Foreground */.fg-card{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:clamp(200px,60%,320px);background:rgba(4,6,12,.8);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border:1px solid rgba(255,255,255,.1);border-radius:10px;padding:24px;z-index:10;text-align:center}- .fg-eyebrow{font-size:9px;letter-spacing:2px;text-transform:uppercase;color:var(--ui-accent);margin-bottom:10px}- .fg-title{font-family:Georgia,serif;font-size:clamp(16px,2vw,22px);color:#fff;margin-bottom:10px;font-style:italic;line-height:1.2}- .fg-body{font-size:11px;color:rgba(255,255,255,.5);line-height:1.6}- 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: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}- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}- .color-row{display:flex;flex-wrap:wrap;gap:8px;align-items:center;font-size:10px;color:var(--ui-muted)}- @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:420px}.stage{flex:none}input[type=color]{height:44px}}- @media(prefers-reduced-motion:reduce){.pattern-layer{transition:none!important}.auto-drift{animation-duration:300s!important}}+ .fg-eyebrow{font-size:11px;font-weight:600;letter-spacing:2px;text-transform:uppercase;color:var(--ui-accent);margin-bottom:10px}+ .fg-title{font-size:clamp(16px,2vw,22px);font-weight:700;color:#fff;margin-bottom:10px;line-height:1.2;text-wrap:balance}+ .fg-body{font-size:13px;color:rgba(255,255,255,.72);line-height:1.6}+ /* On phones and short screens the stage is small, so the card shrinks to leave the grid in view */+ @media(max-width:600px),(max-height:760px){+ .fg-card{padding:12px 14px}+ .fg-eyebrow{margin-bottom:4px}+ .fg-title{margin-bottom:0}+ .fg-body{display:none}+ }</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=3">+ <script src="../../../assets/js/demo-page.js?v=3" 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="../floating-elements/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../abstract-geometric-motion/" 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/07-ambient-background/grid-dot-pattern-parallax/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Grid / Dot Pattern Parallax</h1>- <p>Subtle background pattern translates opposite to mouse movement — imperceptible depth, very effective.</p>-</header>-<div class="layout">- <div class="stage" id="stage">- <div class="pattern-layer2" id="layer2"><div class="pat-layer2"></div></div>- <div class="pattern-layer" id="layer1">- <div class="pat-dots" id="pat-dots"></div>- <div class="pat-lines" id="pat-lines"></div>- <div class="pat-cross" id="pat-cross"></div>+<body class="hb" data-hb-kind="loop">+<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="../floating-elements/" rel="prev" aria-label="Previous: Floating Elements"><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>Floating Elements</span></a><a href="../abstract-geometric-motion/" rel="next" aria-label="Next: Abstract Geometric Motion"><span><span class="hb-dir">Next: </span>Abstract Geometric Motion</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">07.11 · Ambient & Background</p>+ <h1>Grid / Dot Pattern Parallax</h1>+ <p class="hb-lede">A dot grid shifts gently against your pointer for depth. Best for tech sites.</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">Watch it</h2><p>It drifts by itself. Move your pointer over it, or drag a finger sideways across it, and the grid shifts the other way.</p></div>+ </div>+ <div class="stage">+ <div class="pattern-layer2" id="layer2" aria-hidden="true"><div class="pat-layer2"></div></div>+ <div class="pattern-layer" id="layer1" aria-hidden="true">+ <div class="pat-dots" id="pat-dots"></div>+ <div class="pat-lines" id="pat-lines"></div>+ <div class="pat-cross" id="pat-cross"></div>+ </div>+ <div class="spotlight" id="spotlight" aria-hidden="true"></div>+ <div class="cursor" id="cursor" aria-hidden="true"></div>+ <div class="fg-card">+ <div class="fg-eyebrow">Dot grid parallax</div>+ <div class="fg-title">Move your pointer or finger across it</div>+ <div class="fg-body">The grid shifts slightly against your pointer: depth you feel more than see.</div>+ </div>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>+ </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 and see the difference as it moves.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="pat-lbl">Pattern</p>+ <div class="seg" id="pat-seg" role="group" aria-labelledby="pat-lbl">+ <button type="button" data-pat="dots" class="on" aria-pressed="true">Dots</button>+ <button type="button" data-pat="lines" aria-pressed="false">Lines</button>+ <button type="button" data-pat="cross" aria-pressed="false">Dots and lines</button>+ </div>+ <p class="hb-hint">The shape of the grid.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="str-lbl">Strength</p>+ <div class="seg" id="str-seg" role="group" aria-labelledby="str-lbl">+ <button type="button" data-pct="3" aria-pressed="false">Subtle</button>+ <button type="button" data-pct="5" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-pct="10" aria-pressed="false">Strong</button>+ </div>+ <p class="hb-hint">Under 10% of the pointer's move is felt, not seen.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="gap-lbl">Spacing</p>+ <div class="seg" id="gap-seg" role="group" aria-labelledby="gap-lbl">+ <button type="button" data-px="20" aria-pressed="false">Tight</button>+ <button type="button" data-px="28" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-px="44" aria-pressed="false">Wide</button>+ </div>+ <p class="hb-hint">The distance between the dots or lines.</p>+ </div>+ </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="color-lbl">Pattern color</p>+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">+ <button type="button" aria-pressed="false" aria-label="Pink" data-rgb="255,111,139" style="background:#ff6f8b"></button>+ <button type="button" aria-pressed="false" aria-label="White" data-rgb="244,244,242" style="background:#f4f4f2"></button>+ <button type="button" class="on" aria-pressed="true" aria-label="Blue" data-rgb="88,166,255" style="background:#58a6ff"></button>+ <button type="button" aria-pressed="false" aria-label="Purple" data-rgb="210,168,255" style="background:#d2a8ff"></button>+ <button type="button" aria-pressed="false" aria-label="Green" data-rgb="86,211,100" style="background:#56d364"></button>+ <button type="button" aria-pressed="false" aria-label="Orange" data-rgb="255,166,87" style="background:#ffa657"></button>+ </div>+ <p class="hb-hint">The color of the dots and lines.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Second layer</span><input class="hb-switch" type="checkbox" role="switch" id="layer2-tog" autocomplete="off"></label>+ <p class="hb-hint">A sparser layer moves half as far, adding depth.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Light under the pointer</span><input class="hb-switch" type="checkbox" role="switch" id="spot-tog" checked autocomplete="off"></label>+ <p class="hb-hint">A faint glow follows your pointer.</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 dot grid parallax background to [the section you want a subtle sense of depth behind]. Tile a faint grid of dots or lines behind the content, a little larger than the section, and shift it slightly in the opposite direction to the pointer, so it seems to sit deeper than the content. Keep the shift to a few percent of the pointer's movement, so it is felt more than seen. On touch screens, let it follow a dragging finger the same way, and when nothing is over it, let it drift slowly by itself. If the visitor has reduced motion turned on, keep the grid still. 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="spotlight" id="spotlight"></div>- <div class="cursor" id="cursor"></div>- <div class="fg-card">- <div class="fg-eyebrow">Dot Grid Parallax</div>- <div class="fg-title">Move your mouse across the stage</div>- <div class="fg-body">The pattern shifts slightly opposite to your cursor — a depth illusion so subtle you almost don't notice it.</div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Tech and developer sites</li><li>Hero sections</li><li>Dashboards</li><li>Portfolios</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Photo backgrounds</li><li>Long reading pages</li></ul></div>- </div>- <aside>- <p class="note">Keep parallax under 10% of cursor movement. Higher values look like wallpaper sliding. Linear's marketing site uses this pattern beautifully.</p>- <div class="lbl">Pattern</div>- <select id="pat-sel">- <option value="dots" selected>Dot grid</option>- <option value="lines">Line grid</option>- <option value="cross">Cross-hatch</option>- </select>- <div class="lbl">Dot Spacing</div>- <div class="sr"><input type="range" id="gap-sl" min="16" max="60" value="28" step="4"><span class="sv" id="gap-v">28px</span></div>- <div class="lbl">Parallax Strength</div>- <div class="sr"><input type="range" id="str-sl" min="0" max="15" value="5" step="1"><span class="sv" id="str-v">5%</span></div>- <div class="lbl">Colors</div>- <div class="color-row"><span>Pattern</span><input type="color" id="dot-color" value="#58a6ff" aria-label="Pattern color"><span>Background</span><input type="color" id="bg-color" value="#04060c" aria-label="Background color"></div>- <label class="tog"><input type="checkbox" id="layer2-tog"><span>Two layers (depth)</span></label>- <label class="tog"><input type="checkbox" id="spot-tog" checked><span>Spotlight under cursor</span></label>- <div class="div"></div>- <p style="font-size:10px;color:var(--ui-muted)">No mouse? Auto-drifts on touch.</p>- </aside>-</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 layer1=document.getElementById('layer1');- const layer2=document.getElementById('layer2');- const spotlight=document.getElementById('spotlight');- const cursor=document.getElementById('cursor');- const stage=document.getElementById('stage');- let W=0,H=0,str=5,spotOn=true,hasMouse=false,raf=null,autoT=0;- const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');+ const stage=document.querySelector('.stage');+ const layer1=document.getElementById('layer1'),layer2=document.getElementById('layer2');+ const light=document.getElementById('spotlight'),ring=document.getElementById('cursor');+ const PATTERNS={dots:document.getElementById('pat-dots'),lines:document.getElementById('pat-lines'),cross:document.getElementById('pat-cross')};+ const vars=document.documentElement.style;+ let W=0,H=0,str=5,spotOn=true;+ let raf=null,last=null,paused=false;+ let clock=0; // the drift's own time in ms: it moves only while the drift runs, so Play never jumps+ let hasMouse=false; // a mouse is over the stage+ const fingers=new Set(); // fingers and pens that are down on the stage++ const move=(el,x,y)=>{el.style.transform=`translate(${x.toFixed(1)}px,${y.toFixed(1)}px)`};+ // Ring and light sit at the pointer through transform, centred on it+ const put=(el,x,y)=>{el.style.transform=`translate(${x.toFixed(1)}px,${y.toFixed(1)}px) translate(-50%,-50%)`};- function resize(){W=stage.clientWidth;H=stage.clientHeight;}- resize();window.addEventListener('resize',resize);+ // The grid at the drift's clock: strength is a share of the stage, and the two axes drift out of step+ function place(){+ move(layer1,-Math.sin(clock*.0002)*str*.01*W*.4,-Math.cos(clock*.00014)*str*.01*H*.3);+ }+ // loop() keeps exactly one frame requested in raf. The first frame after a start has no earlier frame to measure from,+ // so it adds no time; a long gap between frames (a background tab) counts for at most 50 ms.+ function loop(now){+ raf=requestAnimationFrame(loop);+ clock+=last===null?0:Math.min(now-last,50);+ last=now;+ place();+ }+ function start(){if(raf)return;last=null;raf=requestAnimationFrame(loop)}+ function stop(){cancelAnimationFrame(raf);raf=null}+ // The drift runs only while it is playing and nothing is steering the grid+ function resume(){if(!paused&&!hasMouse&&!fingers.size)start()}- stage.addEventListener('mouseenter',()=>{hasMouse=true;cursor.style.display='block';if(raf){cancelAnimationFrame(raf);raf=null;}layer1.classList.remove('auto-drift');});- stage.addEventListener('mouseleave',()=>{hasMouse=false;cursor.style.display='none';spotlight.style.opacity='0';startAuto();});- stage.addEventListener('mousemove',e=>{- const r=stage.getBoundingClientRect();- const x=e.clientX-r.left,y=e.clientY-r.top;- const nx=x/W-.5,ny=y/H-.5;- const dx=(-nx*str*0.01*W).toFixed(1),dy=(-ny*str*0.01*H).toFixed(1);- layer1.style.transform=`translate(${dx}px,${dy}px)`;- if(document.getElementById('layer2-tog').checked)- layer2.style.transform=`translate(${(dx/2).toFixed(1)}px,${(dy/2).toFixed(1)}px)`;- cursor.style.left=x+'px';cursor.style.top=y+'px';- if(spotOn){spotlight.style.left=x+'px';spotlight.style.top=y+'px';spotlight.style.opacity='1';}+ // Registered at the top level, before the shared script (deferred) can run: under reduced motion it pauses the+ // loop on arrival, which this listener must catch. While paused the grid stays where it is.+ document.addEventListener('hb:pause',e=>{+ paused=e.detail.paused;+ if(paused)stop();+ else resume();});- stage.addEventListener('touchstart',()=>{if(raf){cancelAnimationFrame(raf);raf=null;}},{passive:true});- stage.addEventListener('touchend',startAuto,{passive:true});- stage.addEventListener('touchcancel',startAuto,{passive:true});- stage.addEventListener('touchmove',e=>{- const r=stage.getBoundingClientRect();- const x=e.touches[0].clientX-r.left,y=e.touches[0].clientY-r.top;- const nx=x/W-.5,ny=y/H-.5;- layer1.style.transform=`translate(${(-nx*str*0.01*W).toFixed(1)}px,${(-ny*str*0.01*H).toFixed(1)}px)`;- },{passive:true});- function startAuto(){- if(raf!==null)return;- if(reduceMotion.matches){layer1.style.transform='translate(0,0)';return;}- function loop(t){raf=requestAnimationFrame(loop);autoT=t*.0002;- const dx=(-Math.sin(autoT)*str*0.01*W*.4).toFixed(1);- const dy=(-Math.cos(autoT*.7)*str*0.01*H*.3).toFixed(1);- layer1.style.transform=`translate(${dx}px,${dy}px)`;- }- raf=requestAnimationFrame(loop);+ // A setting that changes where the grid sits places it again at once, so the change shows even while the drift is+ // paused (or is paused a moment later, before the next frame). A grid a pointer is steering stays where it is.+ function refresh(){if(!hasMouse&&!fingers.size)place()}+ // A real change of the stage's size places the grid again; a resize that leaves it as it was (a phone's address bar+ // sliding in or out) does nothing.+ function resize(){+ const w=stage.clientWidth,h=stage.clientHeight;+ if(w===W&&h===H)return;+ W=w;H=h;refresh();}- startAuto();- const PAT_ELS={dots:document.getElementById('pat-dots'),lines:document.getElementById('pat-lines'),cross:document.getElementById('pat-cross')};- document.getElementById('pat-sel').addEventListener('change',e=>{- Object.values(PAT_ELS).forEach(el=>el.style.display='none');- PAT_ELS[e.target.value].style.display='block';+ // Pointer events: a mouse steers the grid while it hovers, a finger or pen while it is down. A tap on a phone sends+ // no mouse pointer, so it never leaves a ring or a light behind.+ const at=e=>{const r=stage.getBoundingClientRect();return[e.clientX-r.left,e.clientY-r.top]};+ // The grid shifts against the pointer: up to half the chosen share of the stage each way+ const against=(x,y)=>[-(x/W-.5)*str*.01*W,-(y/H-.5)*str*.01*H];+ function mouseIn(){hasMouse=true;ring.style.display='block';stop()}++ stage.addEventListener('pointerenter',e=>{if(e.pointerType==='mouse')mouseIn()});+ stage.addEventListener('pointerleave',e=>{+ if(e.pointerType!=='mouse')return;+ hasMouse=false;ring.style.display='none';light.style.opacity='0';+ resume();});- document.getElementById('gap-sl').addEventListener('input',e=>{- document.getElementById('gap-v').textContent=e.target.value+'px';- document.documentElement.style.setProperty('--dot-gap',e.target.value+'px');+ stage.addEventListener('pointerdown',e=>{+ if(e.pointerType==='mouse')return;+ fingers.add(e.pointerId);stop();+ // A pen has no implicit capture, so ask for it: the lift is heard even outside the stage+ try{stage.setPointerCapture(e.pointerId)}catch(_){}+ if(!paused)move(layer1,...against(...at(e)));});- document.getElementById('str-sl').addEventListener('input',e=>{str=+e.target.value;document.getElementById('str-v').textContent=str+'%';});- document.getElementById('dot-color').addEventListener('input',e=>{- const h=e.target.value;const r=parseInt(h.slice(1,3),16),g=parseInt(h.slice(3,5),16),b=parseInt(h.slice(5,7),16);- document.documentElement.style.setProperty('--dot-color',`rgba(${r},${g},${b},.25)`);- spotlight.style.background=`radial-gradient(circle,rgba(${r},${g},${b},.06) 0%,transparent 70%)`;+ stage.addEventListener('pointermove',e=>{+ const [x,y]=at(e);+ if(e.pointerType==='mouse'){+ if(!hasMouse)mouseIn();+ put(ring,x,y); // the ring replaces the system pointer, so it follows even while paused+ if(paused)return;+ const [dx,dy]=against(x,y);+ move(layer1,dx,dy);move(layer2,dx/2,dy/2);+ if(spotOn){put(light,x,y);light.style.opacity='1'}+ }else if(fingers.has(e.pointerId)&&!paused){+ move(layer1,...against(x,y));+ }});- document.getElementById('bg-color').addEventListener('input',e=>{- document.documentElement.style.setProperty('--bg-color',e.target.value);+ // A finger or pen is up when the browser says so, or when the capture asked for above is gone; lifting twice is harmless+ const lift=e=>{if(fingers.delete(e.pointerId))resume()};+ ['pointerup','pointercancel','lostpointercapture'].forEach(type=>stage.addEventListener(type,lift));++ 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('pat-seg',d=>{Object.keys(PATTERNS).forEach(k=>{PATTERNS[k].style.display=k===d.pat?'block':'none'})});+ choices('str-seg',d=>{str=+d.pct;refresh()});+ choices('gap-seg',d=>{vars.setProperty('--dot-gap',d.px+'px')});+ choices('color-sw',d=>{+ vars.setProperty('--dot-color',`rgba(${d.rgb},.25)`);+ light.style.background=`radial-gradient(circle,rgba(${d.rgb},.06) 0%,transparent 70%)`;});- document.getElementById('layer2-tog').addEventListener('change',e=>{layer2.style.display=e.target.checked?'block':'none';});- document.getElementById('spot-tog').addEventListener('change',e=>{spotOn=e.target.checked;if(!spotOn)spotlight.style.opacity='0';});+ document.getElementById('layer2-tog').addEventListener('change',e=>{layer2.style.display=e.target.checked?'block':'none'});+ document.getElementById('spot-tog').addEventListener('change',e=>{spotOn=e.target.checked;if(!spotOn)light.style.opacity='0'});++ resize();+ place();+ window.addEventListener('resize',resize);+ start();</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 c8b2312d..8d867fb9 100644--- a/index.html+++ b/index.html@@ -1043,7 +1043,7 @@ const CATS=[['breathing-glow','Breathing / Pulsing Glow','A soft glow slowly grows and shrinks, like calm breathing. Best for idle states.'],['ambient-ripple','Ambient Ripple Effect','Rings spread from a few spots, like drops on a still pond. Best for hero areas.'],['floating-elements','Floating Elements','Small shapes drift slowly, each on its own path. Best for hero backgrounds.'],- ['grid-dot-pattern-parallax','Grid / Dot Pattern Parallax','Pattern shifts subtly opposite to mouse movement — depth felt, barely seen.'],+ ['grid-dot-pattern-parallax','Grid / Dot Pattern Parallax','A dot grid shifts gently against your pointer for depth. Best for tech sites.'],['abstract-geometric-motion','Abstract Geometric Motion','Four hypnotic loops: rotating polygons, expanding rings, sliding bars, flowing color lines.'],['particle-constellation','Particle Constellation','Drifting nodes link with lines when they come close — the network-mesh hero background.'],['flow-field','Flow Field','Particles follow a noise-driven vector field, leaving flowing trails.'],