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: Overlay Wipe swaps once the panel is in and sends it out after, with every Show me near four seconds
matineb2bd947c56e
diff --git a/animations/03-page-transitions/overlay-wipe/README.md b/animations/03-page-transitions/overlay-wipe/README.mdindex 63f7fd98..b4c38c21 100644--- a/animations/03-page-transitions/overlay-wipe/README.md+++ b/animations/03-page-transitions/overlay-wipe/README.md@@ -10,26 +10,23 @@ An overlay wipe hides a page change behind a solid colored panel. The panel swee- Any change where the old and new page have nothing in common to animate between## How it works-Each panel is an absolutely placed box over the page area. One Web Animations call per panel holds its whole run as keyframes on `transform`: it waits, slides in, covers the page, slides out and stays out of view. The page is swapped by a timer in the middle of the covered moment, and the panels are taken away once the run has ended:+Each panel is an absolutely placed box over the page area, and each slide is one Web Animations call on `transform` that holds where it ends. The change runs in three steps, each started when the one before has finished: the panels slide in; once the front panel's slide in has finished, the page behind it is swapped; only then do the panels slide out, after a short covered moment, and when the last one is out of view they are taken away:```js-function sweep(el,start,ms,stay,total){- const at=t=>t/total;- el.animate([- {transform:FROM[dir],offset:0},{transform:FROM[dir],offset:at(start),easing:EASE},- {transform:'none',offset:at(start+ms)},{transform:'none',offset:at(start+ms+stay),easing:EASE},- {transform:TO[dir],offset:at(start+2*ms+stay)},{transform:TO[dir],offset:1}- ],{duration:total,fill:'both'});+function slide(el,from,to,ms,wait){+ return el.animate([{transform:from},{transform:to}],{duration:ms,delay:wait,easing:EASE,fill:'both'});}// in navigate():-const ms=sweepMs*(slowTog.checked?3:1),stay=ms/3,two=twoTog.checked,lead=two?ms*.35:0,total=2*ms+stay+2*lead;-if(two)sweep(back,0,ms,stay+2*lead,total); // the lighter panel goes in first and comes out last-sweep(front,lead,ms,stay,total);-later(()=>{rest(oldEl,false);rest(newEl,true)},lead+ms+stay/2); // the swap, while the page is covered-later(()=>{clearWipe();finish()},total+30);+const ms=sweepMs*(slowTog.checked?3:1),stay=ms/4,two=twoTog.checked,lead=two?ms/4:0,from=FROM[dir],to=TO[dir];+if(two)slide(back,from,'none',ms,0); // the lighter panel goes in first+slide(front,from,'none',ms,lead).onfinish=()=>{ // 1. in: the page is now covered+ rest(oldEl,false);rest(newEl,true); // 2. swap behind the panel+ const out=slide(front,'none',to,ms,stay),last=two?slide(back,'none',to,ms,stay+lead):out;+ last.onfinish=()=>{clearWipe();finish()}; // 3. out: the lighter panel leaves last+};```-`FROM` and `TO` hold the two off-page places for each direction (for Left to right, `translateX(-100%)` and `translateX(100%)`), so the panel always leaves on the side opposite the one it came from. The easing `cubic-bezier(.7,0,.3,1)` starts and stops each sweep softly and crosses the middle fast. Only `transform` changes, so the browser can move the panels without laying out or repainting the page.+The panels move on the compositor while the swap runs on the main thread. A swap started by a timer can come late when the main thread is busy, and the panel may already have left; chained this way, a busy moment only makes the covered moment longer. `FROM` and `TO` hold the two off-page places for each direction (for Left to right, `translateX(-100%)` and `translateX(100%)`), so the panel always leaves on the side opposite the one it came from. The easing `cubic-bezier(.7,0,.3,1)` starts and stops each sweep softly and crosses the middle fast. Only `transform` changes, so the browser can move the panels without laying out or repainting the page.## Key parameters| Parameter | Default | Effect |@@ -37,11 +34,11 @@ later(()=>{clearWipe();finish()},total+30);| Direction | Left to right | The side the panel comes in from; it always leaves on the opposite side || Panel color | Violet | The color of the panel; the second panel is a lighter shade of it || Two stacked panels | off | A lighter panel runs just ahead of the main one on the way in and just behind it on the way out |-| Speed | Normal | How long each sweep takes: slow is 700ms, normal 450ms and fast 300ms; the page stays covered for a third of that |+| Speed | Normal | How long each sweep takes: slow is 550ms, normal 400ms and fast 270ms; the page stays covered for a quarter of that |## Production notes- **Slide, never resize.** Growing the panel's width or height makes the browser lay out the page on every frame; a `transform` moves an already painted layer.-- **Swap only while covered.** Changing the page before the panel fully covers it shows a cut through the gap. Time the swap from the middle of the covered moment, not from the start of the sweep.+- **Swap only while covered, and chain the steps.** Changing the page before the panel fully covers it shows a cut through the gap, and a swap timed by a timer can come after the panel has already left if the main thread stalls. Swap when the slide in has finished, and start the slide out from there.- **Real page loads.** On a multi-page site, play the first half (in) before leaving the page and the second half (out) on the new page; the View Transitions API can do both halves with `::view-transition-old` and `::view-transition-new` and a pseudo-element for the panel. Barba.js `leave` and `enter` hooks map onto the same two halves.- **Keep it short.** A wipe on every click of an app used all day gets tiring; under a second for the whole change is a good ceiling.- **Reduced motion** skips the panels and fades the new page in over 250ms.diff --git a/animations/03-page-transitions/overlay-wipe/index.html b/animations/03-page-transitions/overlay-wipe/index.htmlindex cfa28f85..ee9a83f7 100644--- a/animations/03-page-transitions/overlay-wipe/index.html+++ b/animations/03-page-transitions/overlay-wipe/index.html@@ -121,9 +121,9 @@<div class="hb-setting"><p class="hb-setting-name" id="speed-lbl">Speed</p><div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">- <button type="button" data-ms="700" aria-pressed="false">Slow</button>- <button type="button" data-ms="450" class="on" aria-pressed="true">Normal</button>- <button type="button" data-ms="300" aria-pressed="false">Fast</button>+ <button type="button" data-ms="550" aria-pressed="false">Slow</button>+ <button type="button" data-ms="400" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="270" aria-pressed="false">Fast</button></div><p class="hb-hint">How long each sweep of the panel takes.</p></div>@@ -182,7 +182,7 @@const FROM={ltr:'translateX(-100%)',rtl:'translateX(100%)',btt:'translateY(100%)',ttb:'translateY(-100%)'};const TO={ltr:'translateX(100%)',rtl:'translateX(-100%)',btt:'translateY(-100%)',ttb:'translateY(100%)'};const EASE='cubic-bezier(.7,0,.3,1)';- let current=0,animating=false,dir='ltr',sweepMs=450,afterMove=null,wayBack=0,timers=[];+ let current=0,animating=false,dir='ltr',sweepMs=400,afterMove=null,wayBack=0,timers=[];const pages=[],navBtns=[];PAGES.forEach((p,i)=>{@@ -236,14 +236,9 @@showPage(current);}- // One panel: it waits `start` ms, slides in over `ms`, covers the page for `stay` ms and slides out over `ms`; `total` is the whole change- function sweep(el,start,ms,stay,total){- const at=t=>t/total;- el.animate([- {transform:FROM[dir],offset:0},{transform:FROM[dir],offset:at(start),easing:EASE},- {transform:'none',offset:at(start+ms)},{transform:'none',offset:at(start+ms+stay),easing:EASE},- {transform:TO[dir],offset:at(start+2*ms+stay)},{transform:TO[dir],offset:1}- ],{duration:total,fill:'both'});+ // One panel slides from `from` to `to` over `ms`, after waiting `wait` ms, and holds where it ends+ function slide(el,from,to,ms,wait){+ return el.animate([{transform:from},{transform:to}],{duration:ms,delay:wait,easing:EASE,fill:'both'});}function navigate(next,then){@@ -258,16 +253,19 @@later(()=>{rest(oldEl,false);rest(newEl,true);finish()},300);return;}- // Read when the change starts; three times as long in slow motion. The page is covered for a third of a sweep.- const ms=sweepMs*(slowTog.checked?3:1),stay=ms/3,two=twoTog.checked,lead=two?ms*.35:0,total=2*ms+stay+2*lead;+ // Read when the change starts; three times as long in slow motion. The page stays covered for a quarter of a sweep.+ const ms=sweepMs*(slowTog.checked?3:1),stay=ms/4,two=twoTog.checked,lead=two?ms/4:0,from=FROM[dir],to=TO[dir];nameEl.textContent=PAGES[next].name;back.hidden=!two;wipe.classList.add('on');- // With two panels the lighter one goes in first and comes out last, so it leads the way in and trails on the way out- if(two)sweep(back,0,ms,stay+2*lead,total);- sweep(front,lead,ms,stay,total);- later(()=>{rest(oldEl,false);rest(newEl,true)},lead+ms+stay/2); // the swap, while the page is covered- later(()=>{clearWipe();finish()},total+30);+ // In, swap, out: each step starts when the one before has finished, so a busy moment can delay the change but never+ // uncover the old page. With two panels the lighter one goes in first and comes out last: it leads in and trails out.+ if(two)slide(back,from,'none',ms,0);+ slide(front,from,'none',ms,lead).onfinish=()=>{+ rest(oldEl,false);rest(newEl,true);+ const out=slide(front,'none',to,ms,stay),last=two?slide(back,'none',to,ms,stay+lead):out;+ last.onfinish=()=>{clearWipe();finish()};+ };}// Show me: one visit to the next page, a hold of 1200ms, and the way back to where the run started