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: Pixelate Transition review: the pose stays off in a run's hold, the See inside arrow starts at its label, the README says each pixel is sampled near its block's middle
matin01815e3a1c6c
diff --git a/animations/03-page-transitions/pixelate-transition/README.md b/animations/03-page-transitions/pixelate-transition/README.mdindex 86050c2c..d435baaf 100644--- a/animations/03-page-transitions/pixelate-transition/README.md+++ b/animations/03-page-transitions/pixelate-transition/README.md@@ -12,7 +12,7 @@ A pixelate transition hides the change from one page or picture to the next behi- A playful change between the sections of a landing page## How it works-The pages are pictures drawn once onto hidden canvases. During a change, each frame draws the current page very small on a second canvas, one pixel per block, with smoothing on, so each pixel becomes the average color of its block; then it draws that small copy back up to the full size with smoothing off, so every pixel turns into one flat square:+The pages are pictures drawn once onto hidden canvases. During a change, each frame draws the current page very small on a second canvas, one pixel per block, with smoothing on, so each pixel takes its color from the middle of its block; then it draws that small copy back up to the full size with smoothing off, so every pixel turns into one flat square:```jsconst bw = Math.ceil(w / b), bh = Math.ceil(h / b); // b: the block size this frame@@ -42,6 +42,7 @@ A change runs by the time that has passed, three times as long in slow motion, a- **Pictures, not live pages.** A canvas cannot pixelate HTML. For real pages, take a picture of each view first (html2canvas or a server-side screenshot), or pixelate only the hero picture and fade the rest. With the View Transitions API, the old and new views can be shown as pictures that a shader or canvas pixelates.- **WebGL.** A fragment shader that rounds each pixel's coordinates to its block (`floor(uv * blocks) / blocks`) pixelates a full-screen view in one pass; PixiJS has a ready-made pixelate filter.- **Keep text readable.** Leave navigation and buttons out of the pixelated area, and keep the change short: it hides the page for a moment by design.+- **Sampled, not averaged.** The small copy takes a spot near each block's middle rather than averaging the whole block, which is close enough for flat squares. For a true average, set the small canvas's smoothing quality to medium or high, which costs more per frame.- **Reduced motion.** Use a short, plain crossfade instead.## See alsodiff --git a/animations/03-page-transitions/pixelate-transition/index.html b/animations/03-page-transitions/pixelate-transition/index.htmlindex 851c72b5..2c8d89e3 100644--- a/animations/03-page-transitions/pixelate-transition/index.html+++ b/animations/03-page-transitions/pixelate-transition/index.html@@ -205,7 +205,8 @@ctx.imageSmoothingEnabled=false;ctx.save();ctx.beginPath();ctx.rect(x,y,w,h);ctx.clip();ctx.drawImage(small,0,0,bw,bh,x,y,bw*b,bh*b);ctx.restore();}function draw(){- const w=cvs.width,h=cvs.height,p=change?change.p:null,b=(p===null?1:blockAt(p))*dpr,show=p!==null&&p>=.5?change.to:current;+ const held=!change&&runFrom!==null&&!reduceMQ.matches; // a Show me run's hold: the change's last frame, not the pose (G4)+ const w=cvs.width,h=cvs.height,p=change?change.p:held?1:null,b=(p===null?1:blockAt(p))*dpr,show=change&&p>=.5?change.to:current;ctx.clearRect(0,0,w,h);const fade=!!change&&change.fade!==undefined; // a change under reduced motion: no block grows or shrinks, in any modeif(mode==='compare'){@@ -229,7 +230,10 @@const bw=Math.ceil(w/b),bh=Math.ceil(h/b),rw=Math.ceil(w/(blockMax*dpr)),rh=Math.ceil(h/(blockMax*dpr)),cell=Math.max(2,Math.floor(Math.min(110*dpr/rw,70*dpr/rh))),iw=rw*cell,ih=rh*cell,ix=w-iw-10*dpr,iy=36*dpr;ctx.fillStyle='rgba(11,11,13,.9)';ctx.fillRect(ix-4*dpr,iy-4*dpr,iw+8*dpr,ih+8*dpr);sctx.imageSmoothingEnabled=true;sctx.drawImage(img,0,0,bw,bh);ctx.imageSmoothingEnabled=false;ctx.drawImage(small,0,0,bw,bh,ix,iy,iw,ih);- const ax=ix-6*dpr,ay=iy+ih+6*dpr,tx=w*.42,ty=h*.6;+ // the labels are measured first: Scaled up sits under the inset and the arrow starts at its left end, aiming at least 50px left of it+ const L=['l-copy','l-up','l-swap'].map(id=>{const el=document.getElementById(id);return{el,w:el.offsetWidth,h:el.offsetHeight}});+ const upX=Math.max(6,Math.min(W-L[1].w-6,(ix+iw)/dpr-L[1].w)),upY=(iy+ih)/dpr+12;+ const ax=(upX-6)*dpr,ay=(upY+L[1].h/2)*dpr,tx=Math.min(w*.42,ax-50*dpr),ty=h*.6;ctx.strokeStyle='#ffce5a';ctx.lineWidth=2.5*dpr;ctx.lineCap='round';ctx.beginPath();ctx.moveTo(ax,ay);ctx.lineTo(tx,ty);const a=Math.atan2(ty-ay,tx-ax);ctx.moveTo(tx-10*dpr*Math.cos(a-.5),ty-10*dpr*Math.sin(a-.5));ctx.lineTo(tx,ty);ctx.lineTo(tx-10*dpr*Math.cos(a+.5),ty-10*dpr*Math.sin(a+.5));ctx.stroke();const sx=10*dpr,sw=Math.min(w*.4,180*dpr),sh=34*dpr,sy=h-sh-10*dpr;@@ -238,10 +242,9 @@for(let i=0;i<=60;i++){const q=i/60,y=sy+sh-(blockAt(q)-1)/(blockMax-1)*sh;i?ctx.lineTo(sx+q*sw,y):ctx.moveTo(sx+q*sw,y)}ctx.stroke();ctx.setLineDash([4*dpr,4*dpr]);ctx.strokeStyle='rgba(255,255,255,.6)';ctx.beginPath();ctx.moveTo(sx+sw/2,sy);ctx.lineTo(sx+sw/2,sy+sh);ctx.stroke();ctx.setLineDash([]);const q=p===null?.5:p;ctx.fillStyle='#fff';ctx.beginPath();ctx.arc(sx+q*sw,sy+sh-(blockAt(q)-1)/(blockMax-1)*sh,5*dpr,0,6.283);ctx.fill();- // the small copy's name to its left, Scaled up under it beside where the arrow starts, Swap here over the strip's top; the- // labels are all measured before any moves, so the page lays out once a frame- const L=['l-copy','l-up','l-swap'].map(id=>{const el=document.getElementById(id);return{el,w:el.offsetWidth,h:el.offsetHeight}});- const at=[[ix/dpr-12-L[0].w,iy/dpr],[(ix+iw)/dpr-L[1].w,(iy+ih)/dpr+12],[(sx+sw/2)/dpr-L[2].w/2,sy/dpr-30]];+ // the small copy's name to its left, Scaled up under it where the arrow starts, Swap here over the strip's top (all measured+ // before any moves, so the page lays out once a frame)+ const at=[[ix/dpr-12-L[0].w,iy/dpr],[upX,upY],[(sx+sw/2)/dpr-L[2].w/2,sy/dpr-30]];L.forEach((l,i)=>{l.el.style.left=Math.max(6,Math.min(W-l.w-6,at[i][0]))+'px';l.el.style.top=Math.max(6,Math.min(H-l.h-6,at[i][1]))+'px'});}// A change runs by the time that passed (three times as long in slow motion) and draws only while it runs@@ -271,12 +274,12 @@if(runFrom!==null){const home=runFrom;stopRun();change=null;cancelAnimationFrame(raf);raf=0;current=home;updateNav(home);draw()}else if(change)return; // the visitor's own change is onconst start=current;runFrom=start;- navigate((start+1)%PAGES.length,()=>later(()=>navigate(start,()=>{runFrom=null}),1200));+ navigate((start+1)%PAGES.length,()=>later(()=>navigate(start,()=>{runFrom=null;draw()}),1200));});document.getElementById('btn-reset').addEventListener('click',()=>{stopRun();change=null;cancelAnimationFrame(raf);raf=0;current=0;updateNav(0);draw()});- document.addEventListener('hb:input',()=>{if(runFrom!==null)stopRun()});+ document.addEventListener('hb:input',()=>{if(runFrom!==null){stopRun();if(!change)draw()}});// A run never moves the focus, so focus arriving in the stage while one runs (a Tab to the page names) is the visitor's- document.querySelector('.stage').addEventListener('focusin',e=>{if(e.isTrusted&&runFrom!==null)stopRun()});+ document.querySelector('.stage').addEventListener('focusin',e=>{if(e.isTrusted&&runFrom!==null){stopRun();if(!change)draw()}});// The mode switch draws the mode at oncedocument.addEventListener('hb:mode',e=>{mode=e.detail.mode;cvs.setAttribute('aria-label',LABELS[mode]);if(W)draw()});function resize(){