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: Fade In / Fade Out's two views: leaving Compare mid-fade lets the fade go on, short boxes keep the graph, cards and words inside, the dot keeps to the line when Loop stops a play, Replay in Compare works under reduced motion, and the copy card's words say it appears at once
matin1074e7857413
diff --git a/animations/02-entrance-and-exit/fade-in-out/index.html b/animations/02-entrance-and-exit/fade-in-out/index.htmlindex 6ba6ca22..f6ab1231 100644--- a/animations/02-entrance-and-exit/fade-in-out/index.html+++ b/animations/02-entrance-and-exit/fade-in-out/index.html@@ -36,11 +36,11 @@/* See inside: the card beside a graph of how solid it is over time (below it on phones, filling the room under the card). Theline rises with the fade in, in the shape of the Feel, stays at the top while the card stays, and with Loop on falls with thefade out; the dot rides it as the card plays: across with the time, up with how solid the card is (the script draws it). */- .stage[data-hb-mode="inside"]{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.3fr);align-items:center;- gap:clamp(12px,3vw,32px);padding:clamp(12px,3vw,32px)}+ .stage[data-hb-mode="inside"]{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.3fr);grid-template-rows:minmax(0,1fr);+ align-items:center;gap:clamp(12px,3vw,32px);padding:clamp(12px,3vw,32px)}.stage[data-hb-mode="inside"] .card{justify-self:center}.stage[data-hb-mode="inside"] .graph{display:block}- .graph{position:relative;width:100%;max-width:460px;aspect-ratio:300/170;justify-self:center}+ .graph{position:relative;width:100%;max-width:460px;aspect-ratio:300/170;max-height:100%;justify-self:center}.graph svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}.graph .axis{fill:none;stroke:rgba(244,244,242,.5);stroke-width:1.5}.graph .curve{fill:none;stroke:var(--ui-accent);stroke-width:3;stroke-linecap:round;stroke-linejoin:round}@@ -64,11 +64,15 @@@media(max-width:600px){.stage[data-hb-mode="inside"]{grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr);gap:8px}.stage[data-hb-mode="inside"] .graph{max-width:none;height:100%;aspect-ratio:auto}+ }+ /* Phones and short boxes (a window up to 620px tall, which gives a box of 290px or less): compact cards. Phones, held either+ way: four words at most in the graph. */+ @media(max-width:600px),(max-height:620px){.stage[data-hb-mode="inside"] .card,.stage[data-hb-mode="compare"] .card{padding:14px 16px}.stage[data-hb-mode="inside"] .card-sub,.stage[data-hb-mode="compare"] .card-sub{display:none}.stage[data-hb-mode="inside"] .card-icon,.stage[data-hb-mode="compare"] .card-icon{font-size:22px;margin-bottom:6px}- .graph:has(.xout:not([hidden])) .xstay{display:none}}+ @media(max-width:600px),(max-height:500px){.graph:has(.xout:not([hidden])) .xstay{display:none}}@media(prefers-reduced-motion:reduce){.card{transition:opacity 300ms linear!important}}</style><link rel="stylesheet" href="../../../assets/css/demo-page.css?v=9">@@ -210,16 +214,20 @@const curve=document.getElementById('curve'),dot=document.getElementById('dot');const lblIn=document.getElementById('lbl-in'),lblStay=document.getElementById('lbl-stay'),lblOut=document.getElementById('lbl-out');const lblSolid=graph.querySelector('.y1'),lblClear=graph.querySelector('.y0');- // Compare's first card: a copy that appears and leaves at once (no fade), out of reach of the keyboard and screen readers+ // Compare's first card: a copy that appears and leaves at once (no fade), with words that say so, out of reach of the keyboard+ // and screen readersconst twin=card.cloneNode(true);twin.removeAttribute('id');twin.classList.add('twin');twin.inert=true;twin.setAttribute('aria-hidden','true');+ twin.querySelector('.card-title').textContent='Instant';+ twin.querySelector('.card-sub').textContent='Nothing moves or changes size; it is simply there, all at once.';card.before(twin);// Under reduced motion both views are still pictures, and their notes say soif(!motionOk){document.querySelector('[data-hb-for="inside"]').textContent='The graph shows how solid the card gets over time, shown still: the dot sits where the fade in ends.';document.querySelector('[data-hb-for="compare"]').textContent='Shown still, a fifth of a second in: on the left, Appears at once, the card is fully there; on the right, Fades in, it is only part of the way.';}- let mode='normal',cycleStart=-1e9,dotRaf=0,G={x0:0,x1:0,yt:0,yb:0};+ // falling: the play under way fades out too (it began with Loop on and Loop has not stopped it before its fade out)+ let mode='normal',cycleStart=-1e9,dotRaf=0,G={x0:0,x1:0,yt:0,yb:0},falling=false;function dur(){return slowTog.checked?ms*3:ms}function apply(){@@ -237,15 +245,19 @@setIn(true);if(mode==='inside')ride();}+ // Compare's held moment comes back once a play is over (the reduced fade is 300ms), if Compare is still on show+ function holdLater(){later(()=>{if(mode==='compare')pose(true)},(motionOk?dur():300)+700)}// One play fades in. While Loop is on it then holds, fades out, waits and plays again;// switching Loop off lets the card finish visible. Slow motion stretches the fades, not the waits.- // In Compare a play lifts the pose, and once it is over the right card is held at its moment again.+ // In Compare a play lifts the hold (under reduced motion too: it plays the short fade), then the right card is held again.function cycle(){apply();- if(motionOk)pose(false);+ pose(false);+ falling=loopTog.checked&&motionOk;+ if(mode==='inside')drawGraph();fadeIn();- if(!loopTog.checked||!motionOk){- if(motionOk&&mode==='compare')later(()=>pose(true),dur()+700);+ if(!falling){+ if(mode==='compare')holdLater();return;}later(()=>{@@ -263,8 +275,8 @@for(let i=0;i<30;i++){t=(lo+hi)/2;if(at(a,c,t)<x)lo=t;else hi=t}return at(b,e,t);}- // A play's parts in ms: the fade in and the hold, and with Loop on the fade out and the wait- function parts(){const d=dur();return loopTog.checked&&motionOk?[d,HOLD,d,WAIT]:[d,HOLD]}+ // A play's parts in ms: the fade in and the hold, and when it falls the fade out and the wait+ function parts(){const d=dur();return falling?[d,HOLD,d,WAIT]:[d,HOLD]}function words(t){return t<=400?'about a third of a second':t<=700?'about half a second':t<=1200?'about a second':t<=2000?'about two seconds':'about three seconds'}// The graph, drawn in the box's own pixels: across is time, up is how solid the card is, and each fade has the Feel's own curve.// Its words keep their size and stay off the line, so the dot passes them: the two levels' words end left of the line's start, the@@ -321,8 +333,8 @@// The mode switch: draws the mode at once. The shared script then presses Replay (not under reduced motion), which plays it.document.addEventListener('hb:mode',e=>{const was=mode;mode=e.detail.mode;- // Leaving Compare's held moment shows the card as it now is, at once, with no fade- if(was==='compare'&&mode!=='compare'){card.style.setProperty('transition','none','important');pose(false);void card.offsetWidth;card.style.removeProperty('transition');}+ // Leaving Compare's held moment shows the card as it now is, at once, with no fade (a fade under way goes on)+ if(was==='compare'&&mode!=='compare'&&stage.classList.contains('posed')){card.style.setProperty('transition','none','important');pose(false);void card.offsetWidth;card.style.removeProperty('transition');}pose(mode==='compare'&&!(loopTog.checked&&motionOk));refresh();if(mode==='inside'&&motionOk)ride();@@ -332,10 +344,11 @@const redraw=new ResizeObserver(()=>{if(mode==='inside')refresh()});redraw.observe(graph);redraw.observe(lblClear);document.getElementById('btn-play').addEventListener('click',play);- // Loop off in Compare: the right card is held once the play under way is over (one fading out fades in again, then holds)+ // Loop off: a play still in its fade in or hold ends there (and in Compare is then held); one fading out or waiting plays on to+ // its end, fades in once more, then holds by itselfloopTog.addEventListener('change',()=>{if(loopTog.checked)play();- else if(mode==='compare'&&card.classList.contains('in'))later(()=>pose(true),dur()+700);+ else if(card.classList.contains('in')){falling=false;if(mode==='compare')holdLater()}refresh();});slowTog.addEventListener('change',refresh);