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 (04.31): the grid takes keyboard focus, the light appears in its middle and the arrow keys move it with the same lag as the pointer, and Escape or leaving puts it out
matine7f04a53cf64
diff --git a/animations/04-micro-interactions/spotlight-hover/README.md b/animations/04-micro-interactions/spotlight-hover/README.mdindex 626c7343..25cc6e71 100644--- a/animations/04-micro-interactions/spotlight-hover/README.md+++ b/animations/04-micro-interactions/spotlight-hover/README.md@@ -30,6 +30,8 @@ lx += (tx - lx) * a; ly += (ty - ly) * a;A mouse lights the grid while it moves over it, and the light fades out (an `opacity` transition on a class) when it leaves. A finger lights it where it touches and while it drags: the grid has `touch-action: none` and takes pointer capture, so the drag moves the light instead of scrolling the page, and lifting the finger fades it out.+The grid also takes keyboard focus (`tabindex="0"`), and the light then appears in its middle, or where the keys last left it. Each arrow key press moves it by 6% of the grid's width or height, and it trails with the same lag as behind a pointer; Escape, or moving the focus away, fades it out.+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|diff --git a/animations/04-micro-interactions/spotlight-hover/index.html b/animations/04-micro-interactions/spotlight-hover/index.htmlindex 9eabc1e2..58830721 100644--- a/animations/04-micro-interactions/spotlight-hover/index.html+++ b/animations/04-micro-interactions/spotlight-hover/index.html@@ -26,6 +26,8 @@.stage{display:flex;overflow:hidden;background:#09090b;padding:clamp(12px,2.4vw,24px)}/* touch-action none: a finger dragged over the cards moves the light instead of scrolling the page */.grid{position:relative;flex:1;min-width:0;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));grid-auto-rows:minmax(0,1fr);gap:clamp(8px,1.4vw,14px);touch-action:none;-webkit-user-select:none;user-select:none}+ /* The grid takes keyboard focus (the arrow keys move the light): its ring goes round it, in the stage's padding, not over the cards */+ .hb-page .stage .grid:focus-visible{outline-offset:4px;border-radius:18px}/* A card is a faint frame (its padding is the edge) around an opaque face */.sc{position:relative;overflow:hidden;border-radius:14px;padding:var(--bw);background:rgba(255,255,255,.09)}/* Both lights are the same soft disc, moved to the pointer by transform only: the one behind the face shows only at@@ -70,7 +72,7 @@<div><h2 id="hb-watch-title">Hover it</h2><p>Move your pointer over the cards, drag a finger across them, or press Show me.</p></div></div><div class="stage">- <div class="grid" id="grid">+ <div class="grid" id="grid" tabindex="0" role="group" aria-label="Feature cards"><div class="sc"><span class="eg" aria-hidden="true"></span><div class="face"><span class="fg" aria-hidden="true"></span><svg class="ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 3v18h18"/><path d="m7 15 4-4 3 3 5-6"/></svg><p class="t">Analytics</p><p class="d">See what people click.</p></div></div><div class="sc"><span class="eg" aria-hidden="true"></span><div class="face"><span class="fg" aria-hidden="true"></span><svg class="ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M13 2 4 14h7l-1 8 9-12h-7z"/></svg><p class="t">Automations</p><p class="d">Runs tasks for you.</p></div></div><div class="sc"><span class="eg" aria-hidden="true"></span><div class="face"><span class="fg" aria-hidden="true"></span><svg class="ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 20 6v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z"/></svg><p class="t">Security</p><p class="d">Logins kept safe.</p></div></div>@@ -281,6 +283,32 @@// brings it back where they are.document.addEventListener('hb:input',()=>{if(running()){stopRun();off()}});+ // The keyboard: Tab focuses the grid and the light appears where the keys last left it (kx,ky: shares of the grid's width and+ // height, at first its middle). Each arrow press moves that spot by STEP, from where the light is heading when a pointer+ // placed it, and a held key repeats; the light goes there through aim(), as after a pointer, so it trails with the same lag.+ // Escape puts it out, as the pointer leaving does, and so does the focus leaving after the keys placed it. A run under way+ // stops, as for a pointer. A click or a tap focuses the grid too, but without :focus-visible: then only keys move the light.+ const STEP=0.06,ARROWS={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};+ let kx=.5,ky=.5,keyed=false;+ function aimKeys(){keyed=true;aim(kx*W,ky*H)}+ grid.addEventListener('focus',()=>{+ if(!grid.matches(':focus-visible'))return;+ if(running())stopRun();+ aimKeys();+ });+ grid.addEventListener('blur',()=>{if(keyed){keyed=false;off()}});+ grid.addEventListener('pointermove',()=>{keyed=false});+ grid.addEventListener('keydown',e=>{+ if(e.altKey||e.ctrlKey||e.metaKey)return;+ if(e.key==='Escape'){keyed=false;off();return}+ const d=ARROWS[e.key];+ if(!d)return;+ e.preventDefault();+ if(!keyed&&lit&&W&&H){kx=tx/W;ky=ty/H}+ kx=Math.min(1,Math.max(0,kx+d[0]*STEP));ky=Math.min(1,Math.max(0,ky+d[1]*STEP));+ aimKeys();+ });+function choices(id,pick){const buttons=document.querySelectorAll('#'+id+' button');buttons.forEach(b=>b.addEventListener('click',()=>{