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
fix: Spotlight Hover Glow: the README and a comment say a pointer move reads the grid's rectangle
matin4fb23664dc4f
diff --git a/animations/04-micro-interactions/spotlight-hover/README.md b/animations/04-micro-interactions/spotlight-hover/README.mdindex eda0e2e2..da19f36e 100644--- a/animations/04-micro-interactions/spotlight-hover/README.md+++ b/animations/04-micro-interactions/spotlight-hover/README.md@@ -21,7 +21,7 @@ function draw() {}```-The card places and the disc size are measured on load and again whenever the grid changes size (a `ResizeObserver`), so moving the light reads nothing from the layout. The light trails the pointer by closing a share of the gap on each frame, scaled to the time since the last frame, so the lag is the same on 60 Hz and 120 Hz screens:+The card places and the disc size are measured on load and again whenever the grid changes size (a `ResizeObserver`); on each pointer move the page reads only the grid's own rectangle (`getBoundingClientRect()`), to turn the pointer's position into a spot on the grid. The light trails the pointer by closing a share of the gap on each frame, scaled to the time since the last frame, so the lag is the same on 60 Hz and 120 Hz screens:```jsconst a = 1 - Math.pow(1 - ease, dt / FRAME); // FRAME = 1000 / 60, dt: ms since the last frame@@ -40,7 +40,7 @@ A mouse lights the grid while it moves over it, and the light fades out (an `opa## Production notes- **Move layers, do not repaint them**: the common shortcut writes the pointer position into CSS variables used by a `radial-gradient(circle at var(--x) var(--y), …)`, which repaints every card on every pointer move. Moving finished layers with `transform` leaves the work to the compositor.-- **Measure once**: read the card positions on load and on resize, never in the pointer handler, so moving the pointer forces no layout.+- **Measure once**: read the card positions on load and on resize, never in the pointer handler, which then reads one rectangle (the grid's) instead of one per card. The page only writes transforms, which never change the layout, so that read stays cheap.- **Touch**: touch screens cannot hover, so let a drag move the light (with `touch-action: none` on the grid only, so the page still scrolls around it) or light the card that is tapped.- **Keyboard**: when the cards are links, light the card that has keyboard focus as well, so the effect is not pointer-only.- **Contrast**: the face light brightens the card behind its text; keep it faint enough that the text stays at 4.5:1 or more.diff --git a/animations/04-micro-interactions/spotlight-hover/index.html b/animations/04-micro-interactions/spotlight-hover/index.htmlindex 01088fa1..1eda2b3b 100644--- a/animations/04-micro-interactions/spotlight-hover/index.html+++ b/animations/04-micro-interactions/spotlight-hover/index.html@@ -177,7 +177,7 @@// lx,ly: where the light is; tx,ty: where it is heading (both on the grid, from its top left); W,H: the grid's sizelet lx=0,ly=0,tx=0,ty=0,W=0,H=0,bw=1.5,k=1.15,ease=0.3,lit=false,raf=0,last=null,touchId=null,runTimers=[],runFrame=0;- // Card places and the light's size are measured once and again whenever the grid changes size; nothing is read while it moves+ // Card places and the light's size are measured once and again whenever the grid changes size; a pointer move reads only the grid's rectanglefunction measure(){W=grid.clientWidth;H=grid.clientHeight;bw=parseFloat(getComputedStyle(cards[0].el).paddingLeft)||0;