Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

fix: trim Grid / Dot Pattern Parallax to 295 lines without changing what it does

matinf8cf31414ef4
diff --git a/animations/07-ambient-background/grid-dot-pattern-parallax/index.html b/animations/07-ambient-background/grid-dot-pattern-parallax/index.html
index 069a6d52..5d7573b5 100644
--- a/animations/07-ambient-background/grid-dot-pattern-parallax/index.html
+++ b/animations/07-ambient-background/grid-dot-pattern-parallax/index.html
@@ -27,28 +27,10 @@
.stage{position:relative;overflow:hidden;background:#04060c;cursor:none;touch-action:pan-y}
/* Pattern layer */
.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);
- background-size:var(--dot-gap) var(--dot-gap)
- }
- .pat-lines{
- width:100%;height:100%;
- background-image:linear-gradient(var(--dot-color) 1px,transparent 1px),linear-gradient(90deg,var(--dot-color) 1px,transparent 1px);
- background-size:var(--dot-gap) var(--dot-gap);
- display:none
- }
- .pat-cross{
- width:100%;height:100%;
- background-image:
- linear-gradient(var(--dot-color) 1px,transparent 1px),
- linear-gradient(90deg,var(--dot-color) 1px,transparent 1px),
- radial-gradient(circle,var(--dot-color) var(--dot-size),transparent 0);
- background-size:var(--dot-gap) var(--dot-gap);
- display:none
- }
- /* Light under the pointer and the ring that replaces it: both are placed with transform. The ring sits above the card
- (z-index 11 against its 10), because the stage hides the system pointer there too */
+ .pat-dots{width:100%;height:100%;background-image:radial-gradient(circle,var(--dot-color) var(--dot-size),transparent 0);background-size:var(--dot-gap) var(--dot-gap)}
+ .pat-lines{width:100%;height:100%;background-image:linear-gradient(var(--dot-color) 1px,transparent 1px),linear-gradient(90deg,var(--dot-color) 1px,transparent 1px);background-size:var(--dot-gap) var(--dot-gap);display:none}
+ .pat-cross{width:100%;height:100%;background-image:linear-gradient(var(--dot-color) 1px,transparent 1px),linear-gradient(90deg,var(--dot-color) 1px,transparent 1px),radial-gradient(circle,var(--dot-color) var(--dot-size),transparent 0);background-size:var(--dot-gap) var(--dot-gap);display:none}
+ /* Light under the pointer and the ring that replaces it: both are placed with transform. The ring sits above the card (z-index 11 against its 10), because the stage hides the system pointer there too */
.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:11;display:none}
/* Layer 2 (sparse) */
@@ -60,12 +42,7 @@
.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}
- }
+ @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>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
<script src="../../../assets/js/demo-page.js?v=3" defer></script>
@@ -221,14 +198,12 @@
// 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%)`};
- // The grid at the drift's clock: strength is a share of the stage, and the two axes drift out of step. The second layer
- // goes half as far, as it does for the pointer.
+ // The grid at the drift's clock: strength is a share of the stage, and the two axes drift out of step. The second layer goes half as far, as it does for the pointer.
function place(){
const x=-Math.sin(clock*.0002)*str*.01*W*.4,y=-Math.cos(clock*.00014)*str*.01*H*.3;
move(layer1,x,y);move(layer2,x/2,y/2);
}
- // 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.
+ // 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);
@@ -240,27 +215,23 @@
// The drift runs only while it is playing and nothing is steering the grid
function resume(){if(!paused&&!hasMouse&&!fingers.size)start()}
- // 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.
+ // 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();
});
- // 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.
+ // 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.
+ // 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();
}
- // 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.
+ // 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; the second layer goes half as far
function steer(x,y){