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
feat: Split-Flap Board shows one tile enlarged beside a side view of its hinge, with the count of its flips (See inside) and the word appearing at once above the board flipping (Compare)
matinbb48a77d3fd4
diff --git a/animations/05-text-typography/split-flap-board/index.html b/animations/05-text-typography/split-flap-board/index.htmlindex dfd08f30..9939642a 100644--- a/animations/05-text-typography/split-flap-board/index.html+++ b/animations/05-text-typography/split-flap-board/index.html@@ -45,10 +45,60 @@.flap.down{transform-origin:50% 0}.flap i{position:absolute;inset:0;background:#000;opacity:0}.tile::after{content:'';position:absolute;z-index:2;left:0;right:0;top:calc(50% - 1px);height:2px;background:rgba(0,0,0,.55)}- .row.clearing .half b{opacity:0;transition:opacity .3s linear}+ .row.clearing .half b,.zoom.clearing .half b{opacity:0;transition:opacity .3s linear}.row.pre .half b{opacity:0;transition:none!important}/* Reduced motion: no flipping; each letter fades in, tile after tile */@media(prefers-reduced-motion:reduce){.half b{transition:opacity .4s linear calc(var(--i,0) * 60ms)}}+ /* See inside and Compare. What they add is hidden in Normal; their words are plain words on a dark backing. */+ .board.twin,.zoom,.hinge,.cap{display:none}+ .cap{position:absolute;max-width:100%;padding:3px 7px;border-radius:5px;background:rgba(11,11,13,.92);color:#f4f4f2;font:600 13px/1.25 var(--hb-font);text-wrap:balance}+ .stage[data-hb-mode="inside"],.stage[data-hb-mode="compare"]{container-type:size;position:relative;padding:10px 12px}+ .stage[data-hb-mode="inside"] .board-top,.stage[data-hb-mode="compare"] .board-top{display:none}+ .stage[data-hb-mode="inside"] .board,.stage[data-hb-mode="compare"] .board{padding:0;border:0;border-radius:0;background:none;--gap:clamp(3px,.9cqw,6px)}+ /* See inside: the board in a thin strip; below it one tile up close (its two still halves dashed, the hinge a bright line, its+ flaps outlined in the colors of the side view's arms) beside a side view of the hinge, and the count of flips underneath.+ The strip's tiles and the close tile are sized from the box's own height. */+ .stage[data-hb-mode="inside"]{--arm1:#ff8aa0;--arm2:#6cc4ff;--capH:30px;display:grid;padding-inline:max(12px,calc((100% - 780px) / 2));grid-template-columns:minmax(0,.9fr) minmax(0,1.6fr);+ grid-template-rows:auto minmax(0,1fr) auto;gap:8px clamp(10px,3vw,28px);align-items:stretch;justify-content:normal}+ .stage[data-hb-mode="inside"] .board{grid-column:1/-1;justify-self:center;--tw:min(68px,calc((100cqw - (var(--n,8) - 1) * var(--gap)) / var(--n,8)),11cqh)}+ .stage[data-hb-mode="inside"] .tile.zoomed{outline:2px solid #f2c94c;outline-offset:-2px}+ .stage[data-hb-mode="inside"] .zoom{display:grid;place-items:center;container-type:size;grid-area:2/1;min-height:0}+ .zoom .tile{--tw:min(84cqw,calc(100cqh / 1.4))}+ .zoom .half{outline:2px dashed color-mix(in srgb,var(--ink) 75%,transparent);outline-offset:-4px}+ .zoom .flap.up{outline:2px solid var(--arm1);outline-offset:-2px}+ .zoom .flap.down{outline:2px solid var(--arm2);outline-offset:-2px}+ .zoom .tile::after{top:calc(50% - 1.5px);height:3px;background:#f2c94c;box-shadow:0 0 0 1.5px #0b0b0d}+ .stage[data-hb-mode="inside"] .hinge{display:grid;grid-area:2/2;grid-template-rows:minmax(0,1fr) auto minmax(0,1fr);justify-items:center;container-type:size;min-height:0}+ .hinge svg{width:min(100cqw,calc(100cqh - 2 * var(--capH)));aspect-ratio:1;overflow:visible}+ .hinge .cap{display:block;position:static}+ .hinge .c1{align-self:end;border-left:3px solid var(--arm1)}+ .hinge .c2{align-self:start;border-left:3px solid var(--arm2)}+ .hinge path{fill:none;stroke-linecap:round;stroke-linejoin:round}+ .hinge .still{stroke:rgba(244,244,242,.55);stroke-width:3;stroke-dasharray:4 4}+ .hinge .arc{stroke-width:2.5;stroke-dasharray:.1 5}+ .hinge .tip{stroke-width:2.5}+ .hinge .a1{stroke:var(--arm1)}+ .hinge .a2{stroke:var(--arm2)}+ .hinge .arm{stroke-width:6;stroke-linecap:round;transform-origin:30px 50px}+ .hinge .arm1{stroke:var(--arm1)}+ .hinge .arm2{stroke:var(--arm2)}+ .hinge .pin{fill:#f2c94c}+ .stage[data-hb-mode="inside"] .c3,.stage[data-hb-mode="inside"] .c4{display:block;position:static;justify-self:center;text-align:center}+ .stage[data-hb-mode="inside"] .c3{grid-area:3/2}+ .stage[data-hb-mode="inside"] .c4{grid-area:3/1;visibility:hidden}+ .stage[data-hb-mode="inside"].posed .c4{visibility:visible}+ /* Compare: two bands, one above the other at every width, each clipping its own content: the word on a board that appears at+ once, then the real board. The real board rests part way through a play, with its words, while nothing waits to play again. */+ .stage[data-hb-mode="compare"]{display:grid;grid-template-rows:repeat(2,minmax(0,1fr));padding:0;align-items:stretch;justify-content:normal}+ .stage[data-hb-mode="compare"] .board{display:flex;justify-content:center;align-items:center;overflow:hidden;padding:30px 12px 8px;+ --tw:min(68px,calc((100cqw - 24px - (var(--n,8) - 1) * var(--gap)) / var(--n,8)),calc((50cqh - 40px) / 1.4))}+ .stage[data-hb-mode="compare"] .twin{border-bottom:1px solid rgba(244,244,242,.14)}+ .stage[data-hb-mode="compare"] .side,.stage[data-hb-mode="compare"] .when{display:block;white-space:nowrap;top:6px;left:10px}+ .stage[data-hb-mode="compare"] .side.second,.stage[data-hb-mode="compare"] .when{top:calc(50% + 6px)}+ .stage[data-hb-mode="compare"] .when{left:auto;right:10px;visibility:hidden}+ .stage[data-hb-mode="compare"].posed .when{visibility:visible}+ @media(max-width:600px),(max-height:500px){.cap{font-size:12px}}+ @media(max-width:640px){.stage[data-hb-mode="inside"]{--capH:46px}}</style><link rel="stylesheet" href="../../../assets/css/demo-page.css?v=10"><script src="../../../assets/js/demo-page.js?v=10" defer></script>@@ -71,17 +121,45 @@<span class="hb-num" aria-hidden="true">1</span><div><h2 id="hb-watch-title">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div></div>+ <div class="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>+ <button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>+ <button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>+ </div><div class="stage hb-dots">+ <div class="board twin" aria-hidden="true" inert><div class="row"></div></div><div class="board"><p class="board-top" aria-hidden="true"><span class="lamp"></span>Departures</p><div class="row" id="row" role="img" aria-label="BOARDING"></div></div>+ <div class="zoom" aria-hidden="true" inert></div>+ <div class="hinge" aria-hidden="true">+ <p class="cap c1" data-hb-caption>The old letter's top falls forward on the hinge</p>+ <svg viewBox="0 0 100 100" focusable="false">+ <path class="still" d="M30 8V92"/>+ <path class="arc a1" d="M30 8A42 42 0 0 1 72 50"/><path class="tip a1" d="M67 44l5 7 5-7"/>+ <path class="arc a2" d="M72 50A42 42 0 0 1 30 92"/><path class="tip a2" d="M37 87l-7 5 7 5"/>+ <line class="arm arm1" x1="30" y1="50" x2="30" y2="8"/>+ <line class="arm arm2" x1="30" y1="50" x2="30" y2="92"/>+ <circle class="pin" cx="30" cy="50" r="5"/>+ </svg>+ <p class="cap c2" data-hb-caption>then the next letter's bottom swings down</p>+ </div>+ <p class="cap c3" aria-hidden="true" data-hb-caption>This tile flips 18 times, from A up to R, about 12 flips a second</p>+ <p class="cap c4" aria-hidden="true" data-hb-caption>Shown part way through a flip</p>+ <p class="cap side first" aria-hidden="true" data-hb-caption>Appears at once</p>+ <p class="cap side second" aria-hidden="true" data-hb-caption>Flips</p>+ <p class="cap when" aria-hidden="true" data-hb-caption>Part way through</p></div><div class="hb-player"><button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button><label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop autocomplete="off"><span>Loop</span></label><label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label></div>+ <div class="hb-mode-notes" aria-live="polite">+ <p data-hb-for="inside" hidden>Inside, each tile is two still halves and two flaps on a hinge. Flip after flip, the old letter's top falls and the next one's bottom lands, until the tile reaches its letter.</p>+ <p data-hb-for="compare" hidden>Appears at once puts the word on the board in one go. Flips turns each tile through the alphabet, so the word settles tile by tile, like a real departures board.</p>+ </div></section><section class="hb-step hb-try" aria-labelledby="hb-try-title">@@ -158,11 +236,22 @@<footer class="hb-foot"><span>Animation Handbook</span><a href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener">Source on GitHub</a><a href="#top">Back to top ↑</a></footer><script>const row=document.getElementById('row'),wordIn=document.getElementById('word-in');+ const stage=row.closest('.stage'),board=row.parentNode,twin=stage.querySelector('.twin'),twinRow=twin.firstChild,zoomBox=stage.querySelector('.zoom');+ const arm1=stage.querySelector('.arm1'),arm2=stage.querySelector('.arm2'),count=stage.querySelector('.c3');const vars=document.documentElement.style;const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');const motionOk=()=>!window.matchMedia('(prefers-reduced-motion:reduce)').matches;const DRUM=' ABCDEFGHIJKLMNOPQRSTUVWXYZ',STAGGER=40; // the letters a tile turns through, in order; each tile starts 40ms after the one on its left+ // See inside and Compare. While nothing waits to play again the views rest on a pose: Compare's real board two thirds of a second+ // into a play (sooner for a short word, so something is still turning), See inside's close tile with its top flap two thirds down.+ const POSE_MS=667,POSE_SHARE=.6,POSE_P=Math.sqrt(2/3)/2,NAMES={normal:'',inside:', with one tile shown up close',compare:', twice: appearing at once, then flipping'};let ms=85,flipMs=85,tiles=[],raf=0,clock=0,lastT=null,timers=[]; // ms: the setting; flipMs: the flip time of the play under way+ let mode='normal',text_='BOARDING',zt=null,zi=0,landed=false,boardPosed=false,fading=false; // landed: the word has settled; fading: reduced motion's letters are fading in+ document.addEventListener('hb:mode',e=>{mode=e.detail.mode;label();settle()});+ if(!motionOk()){+ document.querySelector('[data-hb-for="inside"]').textContent='Shown still, part way through one flip: the old letter\'s top half is falling forward on the hinge. Played, each tile flips like this until it reaches its letter.';+ document.querySelector('[data-hb-for="compare"]').textContent='Shown still, part way through: Appears at once already shows the word, while Flips still has its later letters turning through the alphabet.';+ }// The field only ever holds what the board can show (capitals, A to Z, single spaces), so the board, the field and the// "Word" chip always agree. Cleaned as the visitor types, before the shared script reads it; the caret stays in place.@@ -184,53 +273,77 @@wordIn.dispatchEvent(new Event('input',{bubbles:true}));});function word(){return clean(wordIn.value).trim()||'BOARDING'}- // One tile per letter. Each tile keeps its run of letters, from a blank to its own letter, and the flip it is on (k).+ // A tile keeps its run of letters, from a blank to its own letter, and the flip it is on (k).+ function mk(parent,ch,i){+ const el=document.createElement('div');+ el.className='tile';el.setAttribute('aria-hidden','true');el.style.setProperty('--i',i);+ el.innerHTML='<div class="half up"><b></b></div><div class="half down"><b></b></div><div class="flap up"><b></b><i></i></div><div class="flap down"><b></b><i></i></div>';+ parent.appendChild(el);+ const [u,d,f1,f2]=el.children;+ return {el,u:u.firstChild,d:d.firstChild,f1,f2,f1b:f1.firstChild,f2b:f2.firstChild,s1:f1.lastChild,s2:f2.lastChild,seq:DRUM.slice(0,DRUM.indexOf(ch)+1),k:-1};+ }+ // One tile per letter. Compare's first board shows the finished word; See inside's close tile copies the tile with the most flips.function build(text){- row.textContent='';- row.parentNode.style.setProperty('--n',text.length);- row.setAttribute('aria-label',text.trim());- tiles=[...text].map((ch,i)=>{- const el=document.createElement('div');- el.className='tile';el.setAttribute('aria-hidden','true');el.style.setProperty('--i',i);- el.innerHTML='<div class="half up"><b></b></div><div class="half down"><b></b></div><div class="flap up"><b></b><i></i></div><div class="flap down"><b></b><i></i></div>';- row.appendChild(el);- const [u,d,f1,f2]=el.children;- return {u:u.firstChild,d:d.firstChild,f1,f2,f1b:f1.firstChild,f2b:f2.firstChild,s1:f1.lastChild,s2:f2.lastChild,seq:DRUM.slice(0,DRUM.indexOf(ch)+1),k:-1};- });+ row.textContent=twinRow.textContent=zoomBox.textContent='';+ board.style.setProperty('--n',text.length);+ twin.style.setProperty('--n',text.length);+ text_=text.trim();label();+ tiles=[...text].map((ch,i)=>mk(row,ch,i));+ [...text].forEach((ch,i)=>rest(mk(twinRow,ch,i),ch));+ zi=tiles.reduce((best,t,i)=>t.seq.length>tiles[best].seq.length?i:best,0);+ zt=mk(zoomBox,text[zi],zi);rest(zt,' ');+ tiles[zi].el.classList.add('zoomed');+ landed=boardPosed=false;stage.classList.remove('posed');+ caption();}function rest(t,ch){t.u.textContent=t.d.textContent=ch;t.f1.style.visibility=t.f2.style.visibility='hidden'}- function turn(flap,shade,deg){flap.style.visibility='visible';flap.style.transform='rotateX('+deg.toFixed(2)+'deg)';shade.style.opacity=(Math.abs(deg)/180).toFixed(3)}-- // Every frame works out, from the time played, which flip each tile is on and how far through it. During a flip from- // cur to nxt the still top half already shows nxt and the still bottom half still shows cur; cur's top half falls from- // upright to edge-on (speeding up), then nxt's bottom half swings from edge-on down into place (slowing down).- // The clock moves by the time since the last frame (at most 50ms, so a hidden tab does not jump), a third as fast in- // Slow motion.+ function turn(flap,shade,deg){flap.angle=deg;flap.style.visibility='visible';flap.style.transform='rotateX('+deg.toFixed(2)+'deg)';shade.style.opacity=(Math.abs(deg)/180).toFixed(3)}+ // A tile on flip k of its run, p (0 to 1) of the way through it. During a flip from cur to nxt the still top half already shows+ // nxt and the still bottom half still shows cur; cur's top half falls from upright to edge-on (speeding up), then nxt's bottom+ // half swings from edge-on down into place (slowing down).+ function show(t,k,p){+ if(t.k!==k){t.k=k;const cur=t.seq[k],nxt=t.seq[k+1];t.u.textContent=t.f2b.textContent=nxt;t.d.textContent=t.f1b.textContent=cur}+ if(p<.5){const q=p*2;turn(t.f1,t.s1,-90*q*q);t.f2.style.visibility='hidden'}+ else{const q=(p-.5)*2;t.f1.style.visibility='hidden';turn(t.f2,t.s2,90*(1-q)*(1-q))}+ }+ // Tile i at a given time played, flipping fm ms a flip: works out which flip it is on and how far through it.+ // Returns whether it is still waiting or turning.+ function paint(t,i,clk,fm){+ const flips=t.seq.length-1,local=clk-i*STAGGER;+ if(local<0)return true;+ const k=Math.floor(local/fm);+ if(k>=flips){if(t.k!=='done'){t.k='done';rest(t,t.seq[flips])}return false}+ show(t,k,local/fm-k);+ return true;+ }+ // The side view's arms turn by the close tile's flaps, a flap's angle seen from the side+ function arms(){+ const a=zt.f1.style.visibility==='visible',b=zt.f2.style.visibility==='visible';+ arm1.style.opacity=a?1:0;arm2.style.opacity=b?1:0;+ if(a)arm1.style.transform='rotate('+(-zt.f1.angle).toFixed(2)+'deg)';+ if(b)arm2.style.transform='rotate('+(-zt.f2.angle).toFixed(2)+'deg)';+ }+ // Every frame works out, from the time played, which flip each tile is on and how far through it (See inside's close tile the+ // same way, from the same clock). The clock moves by the time since the last frame (at most 50ms, so a hidden tab does not+ // jump), a third as fast in Slow motion.function frame(ts){const dt=lastT===null?0:Math.min(ts-lastT,50);lastT=ts;clock+=dt*(slowTog.checked?1/3:1);let busy=false;- tiles.forEach((t,i)=>{- const flips=t.seq.length-1,local=clock-i*STAGGER;- if(local<0){busy=true;return}- const k=Math.floor(local/flipMs);- if(k>=flips){if(t.k!=='done'){t.k='done';rest(t,t.seq[flips])}return}- busy=true;- if(t.k!==k){t.k=k;const cur=t.seq[k],nxt=t.seq[k+1];t.u.textContent=t.f2b.textContent=nxt;t.d.textContent=t.f1b.textContent=cur}- const p=local/flipMs-k;- if(p<.5){const q=p*2;turn(t.f1,t.s1,-90*q*q);t.f2.style.visibility='hidden'}- else{const q=(p-.5)*2;t.f1.style.visibility='hidden';turn(t.f2,t.s2,90*(1-q)*(1-q))}- });+ for(let i=0;i<tiles.length;i++)if(paint(tiles[i],i,clock,flipMs))busy=true;+ if(mode==='inside'){paint(zt,zi,clock,flipMs);arms()}raf=busy?requestAnimationFrame(frame):0;if(!busy)finished();}function later(fn,wait){timers.push(setTimeout(fn,wait))}+ function setClearing(on){row.classList.toggle('clearing',on);twinRow.classList.toggle('clearing',on);zoomBox.classList.toggle('clearing',on)}// While Loop is on, the word holds 1800ms, the letters fade away and the board flips again from blankfunction finished(){- if(!loopTog.checked||!motionOk())return;+ landed=true;+ if(!loopTog.checked||!motionOk()){settle();return}later(()=>{if(!loopTog.checked)return;- row.classList.add('clearing');+ setClearing(true);later(cycle,400);},1800);}@@ -240,20 +353,55 @@cancelAnimationFrame(raf);raf=0;flipMs=ms;build(word());- row.classList.remove('clearing');+ setClearing(false);if(!motionOk()){tiles.forEach(t=>rest(t,t.seq[t.seq.length-1]));row.classList.add('pre');void row.offsetWidth;row.classList.remove('pre');+ landed=fading=true;settle();+ later(()=>{fading=false;settle()},tiles.length*60+500);return;}tiles.forEach(t=>rest(t,' '));clock=0;lastT=null;raf=requestAnimationFrame(frame);}function play(){timers.forEach(clearTimeout);timers=[];cycle()}++ // The views' rest pictures, drawn at once and again after any change (a play under way is drawn by the frame step): Compare's+ // real board part way through a play, See inside's close tile part way through a flip, while nothing waits to play again.+ function settle(){+ caption();+ if(raf)return;+ const still=!loopTog.checked||!motionOk(),posing=mode==='compare'&&still&&!fading;+ if(posing)poseBoard();else if(boardPosed)unpose();+ if(mode==='inside'){+ if(still)show(zt,zt.seq.length-2,POSE_P);else paint(zt,zi,clock,flipMs);+ arms();+ }+ stage.classList.toggle('posed',posing||(mode==='inside'&&still));+ }+ function poseBoard(){+ boardPosed=true;+ const clk=Math.min(POSE_MS,POSE_SHARE*tiles.reduce((m,t,i)=>Math.max(m,i*STAGGER+(t.seq.length-1)*ms),0));+ tiles.forEach((t,i)=>{if(clk<i*STAGGER){t.k=-1;rest(t,' ')}else paint(t,i,clk,ms)});+ }+ // The real tiles go back at once to what Normal shows: the settled word, or blank before any play+ function unpose(){+ boardPosed=false;+ tiles.forEach(t=>{t.k=landed?'done':-1;rest(t,landed?t.seq[t.seq.length-1]:' ')});+ }+ // The picture is named for the mode on show+ function label(){row.setAttribute('aria-label',text_+NAMES[mode])}+ // The close tile's count of flips and their pace (a third as many a second in Slow motion)+ function caption(){+ const n=zt.seq.length-1,per=Math.round(1000/(raf?flipMs:ms)/(slowTog.checked?3:1));+ const s='This tile flips '+(n>1?n+' times, from A up to ':'once, from blank to ')+zt.seq[n]+', about '+per+' flips a second';+ if(count.textContent!==s)count.textContent=s;+ }document.addEventListener('visibilitychange',()=>{lastT=null});document.getElementById('btn-play').addEventListener('click',play);- loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play();else settle()});+ slowTog.addEventListener('change',caption);function choices(id,pick){const buttons=document.querySelectorAll('#'+id+' button');buttons.forEach(b=>b.addEventListener('click',()=>{@@ -261,7 +409,7 @@pick(b.dataset);}));}- choices('speed-seg',d=>{ms=+d.ms});+ choices('speed-seg',d=>{ms=+d.ms;settle()});choices('color-sw',d=>{vars.setProperty('--tile',d.c);vars.setProperty('--ink',d.ink)});build(word());tiles.forEach(t=>rest(t,' '));</script>