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: Image Distortion on Hover (06.14): the picture takes keyboard focus, the arrow keys move where it bends as the pointer does, Escape or leaving it lets the bending fade, and How it works says so
matinf255da748c09
diff --git a/animations/06-3d-advanced/image-distortion-hover/README.md b/animations/06-3d-advanced/image-distortion-hover/README.mdindex 268b2adb..e5f326ed 100644--- a/animations/06-3d-advanced/image-distortion-hover/README.md+++ b/animations/06-3d-advanced/image-distortion-hover/README.md@@ -52,6 +52,8 @@ vec3 pattern(vec2 uv) {In the demo the pattern stands still, as a real image would: its time value stays at 0, and only the distortion moves. Once the pointer has gone and the fade has finished, the demo stops drawing, and the pointer or Show me starts it again.+The picture also takes keyboard focus, and the keys stand in for the pointer: keyboard focus bends the picture in its middle (or where it last bent, while that fades), and each press of an arrow key moves that spot 6% of the way across the picture (a key held down repeats). Escape or moving focus away lets the bending fade, as the pointer leaving does.+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|diff --git a/animations/06-3d-advanced/image-distortion-hover/index.html b/animations/06-3d-advanced/image-distortion-hover/index.htmlindex e7eab091..a1a32584 100644--- a/animations/06-3d-advanced/image-distortion-hover/index.html+++ b/animations/06-3d-advanced/image-distortion-hover/index.html@@ -24,6 +24,8 @@:root{--ui-accent:#3fd6c4}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}.stage{position:relative;background:#0b0b0d}+ /* Keyboard focus on the picture: the ring goes around the stage, on the page, where it shows against every color of the picture */+ @supports selector(:has(*)){.hb-page .stage:has(> canvas:focus-visible){outline:2px solid var(--ui-accent);outline-offset:3px}.hb-page .stage canvas:focus-visible{outline:none}}canvas{display:block;width:100%;height:100%;touch-action:none}.fallback{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;text-align:center;padding:clamp(16px,4vw,32px);font-size:13px;line-height:1.7;color:rgba(255,255,255,.72);white-space:pre-wrap;overflow-y:auto}</style>@@ -48,7 +50,7 @@<div><h2 id="hb-watch-title">Hover it</h2><p>Move your pointer over the picture, drag a finger across it, or press Show me.</p></div></div><div class="stage" id="stage">- <canvas id="cvs" role="img" aria-label="A blue, purple and green patterned picture with a faint grid, bending where the pointer touches it"></canvas>+ <canvas id="cvs" role="img" tabindex="0" aria-label="A blue, purple and green patterned picture with a faint grid, bending where the pointer touches it. Press the arrow keys to move where it bends."></canvas></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>@@ -295,6 +297,20 @@ if(init()){stage.addEventListener('pointerleave',release);stage.addEventListener('pointerup',e=>{if(e.pointerType!=='mouse')release();});stage.addEventListener('pointercancel',release);+ // The keyboard is a pretend pointer through the same point(): focus by keyboard ends a run and bends the picture where it last+ // bent (the middle once the bending has faded), each arrow key moves that spot 6% of the picture (held, it repeats), and Escape+ // or leaving the picture lets the bending fade as release() does+ const STEP={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};+ let keys=false;+ const keyPoint=(dx,dy)=>{demoStart=0;keys=true;+ point(Math.max(0,Math.min(W,(mouseX<0?W/2:mouseX)+dx*W)),Math.max(0,Math.min(H,(mouseY<0?H/2:mouseY)+dy*H)));wake();};+ cvs.addEventListener('focus',()=>{if(cvs.matches(':focus-visible'))keyPoint(0,0);});+ cvs.addEventListener('keydown',e=>{+ const d=!e.altKey&&!e.ctrlKey&&!e.metaKey&&STEP[e.key];+ if(d){e.preventDefault();keyPoint(.06*d[0],.06*d[1]);}+ else if(e.key==='Escape'&&keys){keys=false;release();}+ });+ cvs.addEventListener('blur',()=>{if(keys){keys=false;release();}});window.addEventListener('resize',()=>{if(layout())draw();});cvs.addEventListener('webglcontextlost',e=>{e.preventDefault();if(raf!==null)cancelAnimationFrame(raf);raf=null;