Skip to content

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.

feat: Portal / Tunnel Zoom shows the next page cut to an opening with ten rings marking its edge every tenth of the time (See inside) and Switches at once beside Opens from portal (Compare)

matin519bafe588c1
diff --git a/animations/03-page-transitions/portal-zoom/index.html b/animations/03-page-transitions/portal-zoom/index.html
index 2612a8aa..b342d606 100644
--- a/animations/03-page-transitions/portal-zoom/index.html
+++ b/animations/03-page-transitions/portal-zoom/index.html
@@ -21,7 +21,7 @@
<meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Portal / Tunnel Zoom", "name": "Portal / Tunnel Zoom", "description": "The next page opens out of a circle you click. Best for big reveals.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/03-page-transitions/portal-zoom/", "inLanguage": "en", "articleSection": "Page Transitions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Page Transitions, Portal / Tunnel Zoom"}</script>
<style>
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#b98cff;--ui-text:#f4f4f2;--ui-muted:#8a8a92;--hb-stage-h-phone:360px}
+ :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#b98cff;--ui-text:#f4f4f2;--ui-muted:#8a8a92;--mark:#ffd84d;--hb-stage-h-phone:360px}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{display:flex;flex-direction:column;overflow:hidden;background:var(--bg);color:var(--ui-text)}
.mini-nav{display:flex;gap:6px;padding:10px 12px;background:var(--ui-bg);border-bottom:1px solid var(--ui-border);flex-shrink:0}
@@ -53,6 +53,59 @@
@media(max-height:640px){.pc{gap:8px}.gi{padding:12px}}
@media(max-height:640px) and (min-width:601px){.portal{top:8px}}
@media(prefers-reduced-motion:reduce){.portal{transition:none}}
+ /* The small site sits in a box, so Compare can lay two of them side by side. In Compare a copy of it, the twin, sits beside it. */
+ .stage{position:relative}
+ .box{display:flex;flex-direction:column;flex:1;min-height:0;min-width:0}
+ .twin,.rings,.cap{display:none}
+ .twin .nav-btn{display:inline-flex;align-items:center}
+ .cap{padding:2px 7px;border-radius:5px;background:#111114;color:#f4f4f2;font:600 12px/1.25 var(--hb-font);white-space:nowrap}
+ .cap.in{position:absolute;left:0;top:0;z-index:6;white-space:normal;max-width:calc(100% - 16px)}
+ /* See inside: ten dashed rings mark where the opening's edge is at each tenth of its time; four ticks (or a dot) mark where it
+ starts; the next page lies on top, cut to the opening, and the portal you click stays above it with its own words */
+ .stage[data-hb-mode="inside"] .rings,.stage[data-hb-mode="inside"] .cap.in{display:block}
+ .rings{position:absolute;inset:0;width:100%;height:100%;z-index:3;pointer-events:none}
+ .rg{fill:none;stroke:rgba(255,255,255,.8);stroke-width:1.5;stroke-dasharray:3 5}
+ .tick{stroke:var(--mark);stroke-width:2.5;stroke-linecap:round}
+ .dot{fill:var(--mark)}
+ .edge{fill:none;stroke:var(--mark);stroke-width:3;vector-effect:non-scaling-stroke;visibility:hidden}
+ .edge.on{visibility:visible}
+ .rings .off{display:none}
+ .rings.go .under{visibility:hidden}
+ .stage[data-hb-mode="inside"] .page.pose,.stage[data-hb-mode="compare"] .page.pose{opacity:1;visibility:visible}
+ .stage[data-hb-mode="inside"] .page.pose .portal,.stage[data-hb-mode="compare"] .page.pose .portal{visibility:hidden}
+ .stage[data-hb-mode="inside"].posed .page.active .portal,.stage[data-hb-mode="compare"].posed .page.active .portal{z-index:4}
+ /* Compare: on the left the copy, which changes page at once; on the right the real site, caught part way through its change. Both
+ halves draw the same page, its text clear of the portal at the top right and of the half's name at the bottom. */
+ .stage[data-hb-mode="compare"]{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:2px;background:#2a2a30}
+ .stage[data-hb-mode="compare"] .twin,.stage[data-hb-mode="compare"] .cap.side{display:block}
+ .stage[data-hb-mode="compare"] .twin{display:flex}
+ .cap.side{position:absolute;bottom:10px;z-index:11}
+ .cap.first{left:10px}
+ .cap.second{left:calc(50% + 10px)}
+ .stage[data-hb-mode="compare"] .pc{padding:12px 16px 44px}
+ .stage[data-hb-mode="compare"] :is(.pe,.ph,.pp){margin-right:clamp(92px,36%,174px)}
+ .stage[data-hb-mode="compare"] .ph{font-size:clamp(16px,2.4vw,24px)}
+ /* Phones and short windows leave a half little room: its page keeps only its eyebrow and heading */
+ @media(max-width:600px),(max-height:650px){
+ .stage[data-hb-mode="compare"] .pp,.stage[data-hb-mode="compare"] .pgrid,.stage[data-hb-mode="compare"] .pstat{display:none}
+ }
+ @media(max-width:600px){
+ .cap.in.wide{max-width:150px}
+ /* In See inside the labels fill the top of the box: the page keeps only its eyebrow and heading, below them */
+ .stage[data-hb-mode="inside"] .pc{justify-content:flex-start;padding-top:136px}
+ .stage[data-hb-mode="inside"] :is(.pp,.pgrid,.pstat){display:none}
+ .stage[data-hb-mode="compare"] .mini-nav{gap:4px;padding:6px}
+ .stage[data-hb-mode="compare"] .nav-btn{padding:0 4px;font-size:12px;min-width:44px;justify-content:center}
+ .stage[data-hb-mode="compare"] .pc{padding:128px 12px 44px;justify-content:flex-start}
+ .stage[data-hb-mode="compare"] :is(.pe,.ph,.pp){margin-right:0}
+ }
+ /* From 360px down the halves stack; a stacked half is short and wide, so its text sits left of the portal */
+ @media(max-width:360px){
+ .stage[data-hb-mode="compare"]{grid-template-columns:minmax(0,1fr);grid-template-rows:repeat(2,minmax(0,1fr))}
+ .cap.first{bottom:calc(50% + 10px)}
+ .cap.second{left:10px}
+ .stage[data-hb-mode="compare"] .pc{padding:12px 88px 44px 12px}
+ }
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=10">
<script src="../../../assets/js/demo-page.js?v=10" defer></script>
@@ -75,15 +128,34 @@
<span class="hb-num" aria-hidden="true">1</span>
<div><h2 id="hb-watch-title">Click it</h2><p>Click the round portal or a page name, or press Show me.</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">
- <nav class="mini-nav" id="nav" aria-label="Demo pages"></nav>
- <div class="page-area" id="page-area"></div>
+ <div class="box" id="box">
+ <nav class="mini-nav" id="nav" aria-label="Demo pages"></nav>
+ <div class="page-area" id="page-area">
+ <svg class="rings" id="rings" aria-hidden="true"></svg>
+ <p class="cap in" aria-hidden="true" data-hb-caption>Starts as a point here</p>
+ <p class="cap in wide" aria-hidden="true" data-hb-caption>The whole next page, cut to the opening</p>
+ <p class="cap in" aria-hidden="true" data-hb-caption>Its edge every tenth of the time</p>
+ <p class="cap in" aria-hidden="true" data-hb-caption>The opening takes about a second</p>
+ </div>
+ </div>
+ <p class="cap side first" aria-hidden="true" data-hb-caption>Switches at once</p>
+ <p class="cap side second" aria-hidden="true" data-hb-caption>Opens from portal</p>
</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>
<button class="hb-play" type="button" id="btn-reset" data-hb-reset><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>Reset</button>
<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, the next page sits on top, cut to an opening growing from a point at the portal; rings mark its edge every tenth of the time. Click the portal or press Show me.</p>
+ <p data-hb-for="compare" hidden>Switches at once simply changes page; Opens from portal grows the next page out of the portal you click. Click the portal or a page name, or press Show me.</p>
+ </div>
</section>
<section class="hb-step hb-try" aria-labelledby="hb-try-title">
@@ -174,10 +246,12 @@
{name:'About',bg:'linear-gradient(135deg,#1f0d26,#2e1540)',portalBg:'#402060',portalLabel:'Return home',
html:`<div class="pc"><div class="pe">Our Story</div><p class="ph">Built on conviction.</p><p class="pp">18 people who care unreasonably about craft. Independent since 2016.</p><div class="pstat"><div><b>140+</b><span>Projects</span></div><div><b>9</b><span>Years</span></div></div></div>`},
];
+ const box=document.getElementById('box'),stage=box.parentElement;
const nav=document.getElementById('nav'),area=document.getElementById('page-area'),slowTog=document.getElementById('slow-tog');
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
let current=0,animating=false,shape='circle',dur=1200,ease='ease-in',afterMove=null,wayBack=0,timers=[],ownFocus=false;
- const pages=[],portals=[],navBtns=[];
+ const pages=[],portals=[],navBtns=[],rings=document.getElementById('rings');
+ let mode='normal',from=null; // from: the portal (or null, a page name) the next change starts at
PAGES.forEach((p,i)=>{
const d=document.createElement('div');d.className='page';d.style.background=p.bg;d.innerHTML=p.html;
@@ -186,7 +260,7 @@
const label=document.createElement('span');label.className='portal-label';label.textContent=p.portalLabel;
portal.appendChild(label);
portal.addEventListener('click',()=>navigate((i+1)%PAGES.length,portal));
- d.appendChild(portal);area.appendChild(d);pages.push(d);portals.push(portal);
+ d.appendChild(portal);area.insertBefore(d,rings);pages.push(d);portals.push(portal);
const b=document.createElement('button');b.type='button';b.className='nav-btn';b.textContent=p.name;
b.addEventListener('click',()=>navigate(i));nav.appendChild(b);navBtns.push(b);
});
@@ -211,12 +285,13 @@
// One page's resting look: its class alone shows or hides it, with the opening's clip, transition and stacking gone (its background stays)
function rest(el,on){
el.classList.toggle('active',on);
+ el.classList.remove('pose');el.inert=false;
el.style.clipPath='';el.style.transition='';el.style.zIndex='';
}
// The resting state for page n, at once. A running opening is cancelled too, so no tail of it shows.
function showPage(n){
pages.forEach((el,i)=>{rest(el,i===n);el.getAnimations().forEach(a=>a.cancel())});
- updateNav(n);
+ updateNav(n);showTwin(n);
}
// Ends an opening: the demo is idle again, and a Show me run goes on to its next step
@@ -227,68 +302,187 @@
if(at&&pages.some(p=>p.contains(at))&&!pages[current].contains(at)){ownFocus=true;portals[current].focus({preventScroll:true});ownFocus=false}
const then=afterMove;afterMove=null;
if(then)then();
+ idle();
}
// Stops everything at once and shows the resting state for `current`
function settle(){
timers.forEach(clearTimeout);timers=[];wayBack=0;afterMove=null;
animating=false;
showPage(current);
+ idle();
+ }
+
+ // Where an opening starts, in % of the page area: the center of the portal that was clicked, or the middle for a page name
+ function startAt(portalEl){
+ const a=area.getBoundingClientRect(),w=a.width,h=a.height;
+ if(!portalEl)return{x:50,y:50,w,h,pr:0};
+ const r=portalEl.getBoundingClientRect();
+ return{x:+((r.left+r.width/2-a.left)/w*100).toFixed(1),y:+((r.top+r.height/2-a.top)/h*100).toFixed(1),w,h,pr:r.width/2};
+ }
+ // The clip of the incoming page when the opening has made the share s (0 to 1) of its way: nothing at the point, then a circle that
+ // ends at 150% (enough to reach the corners) or a square that ends at the whole page area
+ function clipAt(s,o){
+ if(shape==='square'){const k=1-s;return`inset(${(o.y*k).toFixed(1)}% ${((100-o.x)*k).toFixed(1)}% ${((100-o.y)*k).toFixed(1)}% ${(o.x*k).toFixed(1)}%)`}
+ return`circle(${(150*s).toFixed(1)}% at ${o.x.toFixed(1)}% ${o.y.toFixed(1)}%)`;
}
// portalEl is the portal that was clicked; without one (a page name, the way back) the opening starts in the middle of the page area
function navigate(next,portalEl,then){
if(next===current||animating)return;
- const prev=current;current=next;updateNav(next);
+ const prev=current;current=next;updateNav(next);from=portalEl||null;
afterMove=then||null;
if(!motionOk){showPage(next);finish();return}
- animating=true;
+ animating=true;showTwin(next);
const prevEl=pages[prev],nextEl=pages[next],d=dur*(slowTog.checked?3:1); // read when the opening starts; three times as long in slow motion
- const areaRect=area.getBoundingClientRect();
- let px='50%',py='50%';
- if(portalEl){
- const pr=portalEl.getBoundingClientRect();
- px=((pr.left+pr.width/2-areaRect.left)/areaRect.width*100).toFixed(1)+'%';
- py=((pr.top+pr.height/2-areaRect.top)/areaRect.height*100).toFixed(1)+'%';
- }
+ const o=startAt(portalEl);
+ lift();
// Clip the new page to nothing at the portal position, then open it out to fill the page area
- const isSquare=shape==='square';
- const startClip=isSquare?`inset(${py} ${(100-parseFloat(px)).toFixed(1)}% ${(100-parseFloat(py)).toFixed(1)}% ${px})`:`circle(0% at ${px} ${py})`;
- const endClip=isSquare?'inset(0%)':`circle(150% at ${px} ${py})`;
- nextEl.style.clipPath=startClip;nextEl.style.zIndex='2'; // the incoming page paints above the outgoing one whatever the DOM order
+ nextEl.style.clipPath=clipAt(0,o);nextEl.style.zIndex='2'; // the incoming page paints above the outgoing one whatever the DOM order
nextEl.style.transition='none';
nextEl.classList.add('active');
nextEl.offsetHeight; // force reflow: commit the pinhole before the growth is switched on
nextEl.style.transition=`clip-path ${d}ms ${ease}`;
- nextEl.style.clipPath=endClip;
+ nextEl.style.clipPath=clipAt(1,o);
+ if(mode==='inside')runEdge(d);
later(()=>{rest(prevEl,false);rest(nextEl,true);finish()},d+50);
}
// Show me: click the portal of the page on show, hold the new page for 1200ms, then go back the way a page name does
+ // A press that interrupts a run (a mode press makes one) starts again from the page that run started at, so it ends where it began
+ let runFrom=null;
function showMe(){
+ if(runFrom!==null)current=runFrom;
settle();
- const start=current;
- navigate((start+1)%PAGES.length,portals[start],()=>{wayBack=later(()=>{wayBack=0;navigate(start)},1200)});
+ const start=runFrom=current;
+ navigate((start+1)%PAGES.length,portals[start],()=>{wayBack=later(()=>{wayBack=0;navigate(start,null,()=>{runFrom=null})},1200)});
}
- function reset(){current=0;settle()}
+ function reset(){current=0;runFrom=null;settle()}
document.getElementById('btn-demo').addEventListener('click',showMe);
document.getElementById('btn-reset').addEventListener('click',reset);
// The visitor took over: cancel what the run has not started yet. An opening already under way finishes on its own.
- document.addEventListener('hb:input',()=>{afterMove=null;cancel(wayBack);wayBack=0});
+ document.addEventListener('hb:input',()=>{afterMove=null;runFrom=null;cancel(wayBack);wayBack=0});
// A visitor who tabs into the box takes over, as a press does; the page's own focus move (in finish) does not count
- document.querySelector('.stage').addEventListener('focusin',e=>{if(e.isTrusted&&!ownFocus){afterMove=null;cancel(wayBack);wayBack=0}});
+ document.querySelector('.stage').addEventListener('focusin',e=>{if(e.isTrusted&&!ownFocus){afterMove=null;runFrom=null;cancel(wayBack);wayBack=0}});
function choices(id,pick){
const buttons=document.querySelectorAll('#'+id+' button');
buttons.forEach(b=>b.addEventListener('click',()=>{
buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
- pick(b.dataset);
+ pick(b.dataset);draw();
}));
}
choices('shape-seg',d=>{shape=d.shape});
choices('speed-seg',d=>{dur=+d.ms});
choices('feel-seg',d=>{ease=d.ease});
+ slowTog.addEventListener('change',draw);
+
+ // ---- Compare's first half: the same small site as a copy that changes page the moment a change starts. No ids, spans for buttons,
+ // and out of the Tab order and the screen reader's reach.
+ const twin=document.createElement('div');
+ twin.className='box twin';twin.inert=true;twin.setAttribute('aria-hidden','true');
+ twin.innerHTML=`<div class="mini-nav">${PAGES.map(p=>`<span class="nav-btn">${p.name}</span>`).join('')}</div>`+
+ `<div class="page-area">${PAGES.map(p=>`<div class="page" style="background:${p.bg}">${p.html}<span class="portal" style="background:${p.portalBg}"><span class="portal-label">${p.portalLabel}</span></span></div>`).join('')}</div>`;
+ box.before(twin);
+ const twinPages=[...twin.querySelectorAll('.page')],twinNav=[...twin.querySelectorAll('.nav-btn')];
+ function showTwin(n){twinPages.forEach((el,i)=>el.classList.toggle('active',i===n));twinNav.forEach((b,i)=>b.classList.toggle('active',i===n))}
+
+ // ---- See inside and its still. The share of the way the opening has made at time t (0 to 1) comes from the browser's own curve
+ // for the Feel, so the rings sit where the opening's edge really is.
+ const clock=new Animation(new KeyframeEffect(null,null,{duration:1000,fill:'both'}),document.timeline);
+ function shareAt(t){
+ clock.effect.updateTiming({easing:ease});clock.currentTime=t*1000;
+ const p=clock.effect.getComputedTiming().progress;
+ return typeof p==='number'?p:t;
+ }
+ const SVG='http://www.w3.org/2000/svg';
+ const make=(tag,cls)=>{const e=document.createElementNS(SVG,tag);e.setAttribute('class',cls);rings.appendChild(e);return e};
+ const ringEls=Array.from({length:10},()=>make('rect','rg')),edge=make('rect','edge');
+ const tickEls=[45,135,225,315].map(a=>{const l=make('line','tick');l.dataset.a=a;return l});
+ const dot=make('circle','dot');dot.setAttribute('r','5');
+ const caps=[...area.querySelectorAll('.cap.in')];
+ const NUM=['one','two','three','four','five','six'];
+ // A length as a beginner says it
+ function words(ms){
+ const s=ms/1000;
+ if(s<.85)return'about two thirds of a second';
+ if(s<1.5)return'about a second';
+ return`about ${NUM[Math.round(s)-1]} seconds`;
+ }
+ // Under reduced motion both views are still pictures, and their notes say so
+ if(!motionOk){
+ document.querySelector('[data-hb-for="inside"]').textContent='Shown still: the next page on top, cut to an opening caught part way out of the portal, and rings marking its edge every tenth of the time.';
+ document.querySelector('[data-hb-for="compare"]').textContent='Shown still: Switches at once has simply changed page; Opens from portal is caught part way, the next page showing in the opening.';
+ }
+ const setBox=(el,x,y,w,h,r)=>{el.setAttribute('x',x.toFixed(1));el.setAttribute('y',y.toFixed(1));el.setAttribute('width',w.toFixed(1));el.setAttribute('height',h.toFixed(1));el.setAttribute('rx',r.toFixed(1))};
+ // The rings, ticks, outline and labels, from the numbers the change itself uses: where it starts, the page area's size, the
+ // shape, and the share of the way at each tenth of its time
+ function mark(){
+ const o=startAt(from),W=o.w,H=o.h,ox=o.x*W/100,oy=o.y*H/100,R=1.5*Math.hypot(W,H)/Math.SQRT2,square=shape==='square';
+ const shares=ringEls.map((r,i)=>{
+ const s=shareAt((i+1)/10);
+ if(square)setBox(r,ox*(1-s),oy*(1-s),W*s,H*s,0);else setBox(r,ox-R*s,oy-R*s,2*R*s,2*R*s,R*s);
+ r.classList.toggle('under',R*s<o.pr+4);
+ return s;
+ });
+ if(square)setBox(edge,0,0,W,H,0);else setBox(edge,ox-R,oy-R,2*R,2*R,R);
+ edge.style.transformOrigin=`${ox}px ${oy}px`;
+ tickEls.forEach(l=>{
+ const a=l.dataset.a*Math.PI/180,c=Math.cos(a),n=Math.sin(a);
+ l.setAttribute('x1',(ox+c*(o.pr+6)).toFixed(1));l.setAttribute('y1',(oy+n*(o.pr+6)).toFixed(1));
+ l.setAttribute('x2',(ox+c*(o.pr+14)).toFixed(1));l.setAttribute('y2',(oy+n*(o.pr+14)).toFixed(1));
+ l.classList.toggle('off',!o.pr);
+ });
+ dot.setAttribute('cx',ox.toFixed(1));dot.setAttribute('cy',oy.toFixed(1));dot.classList.toggle('off',!!o.pr);
+ // Labels: the first beside the start, the second inside the opening below it, the third on a ring and the length at the bottom
+ const [c1,c2,c3,c4]=caps,g=8;
+ c4.textContent=`The opening ${motionOk?'takes':'would take'} ${words(dur*(slowTog.checked?3:1))}`;
+ const put=(el,x,y)=>{el.style.transform=`translate(${Math.round(Math.max(g,Math.min(x,W-g-el.offsetWidth)))}px,${Math.round(Math.max(g,Math.min(y,H-g-el.offsetHeight)))}px)`};
+ put(c1,ox-(o.pr||6)-g-c1.offsetWidth,oy-c1.offsetHeight/2);
+ put(c2,ox-c2.offsetWidth/2,oy+o.pr+14);
+ put(c4,g,H);
+ const y3=H-g-c4.offsetHeight-6-c3.offsetHeight,yc=y3+c3.offsetHeight/2;
+ let x3=W*.4,gap=1e9;
+ shares.forEach(s=>{
+ const x=square?(yc>=oy*(1-s)&&yc<=oy*(1-s)+H*s?ox*(1-s):NaN):ox-Math.sqrt((R*s)**2-(yc-oy)**2);
+ if(Math.abs(x-W*.4)<gap){gap=Math.abs(x-W*.4);x3=x}
+ });
+ put(c3,x3-c3.offsetWidth/2,y3);
+ }
+ // The outline: the end opening scaled from the start with the length and curve of the clip, started in the same step
+ function runEdge(d){
+ mark();rings.classList.add('go');
+ edge.style.transition='none';edge.style.transform='scale(0)';edge.classList.add('on');
+ edge.getBoundingClientRect(); // commit the point before the growth is switched on
+ edge.style.transition=`transform ${d}ms ${ease}`;edge.style.transform='scale(1)';
+ }
+ function stopEdge(){edge.classList.remove('on');edge.style.transition='none';edge.style.transform='scale(0)';rings.classList.remove('go')}
+ // The incoming page is not shown at rest, so the pose lifts it: visible, inert, cut to the opening at 40% of its time
+ function unpose(){pages.forEach(el=>{if(el.classList.contains('pose')){el.classList.remove('pose');el.inert=false;el.style.clipPath='';el.style.zIndex=''}})}
+ function lift(){stage.classList.remove('posed');unpose()}
+ // At rest in a mode the next change stands caught at 40% of its time, from the portal of the page on show; a change lifts the pose
+ // and it comes back when nothing is pending
+ function pose(){
+ unpose();
+ const still=mode!=='normal'&&!animating;
+ stage.classList.toggle('posed',still); // the portal of the page on show stays above the rings, in the hold of a Show me run too
+ if(!still||wayBack)return;
+ const el=pages[(current+1)%PAGES.length];
+ el.classList.add('pose');el.inert=true;el.style.zIndex='2';
+ el.style.clipPath=clipAt(shareAt(.4),startAt(portals[current]));
+ }
+ function draw(){
+ if(!animating)from=portals[current];
+ if(mode==='inside')mark();
+ pose();
+ }
+ function idle(){stopEdge();draw()}
+ // The mode switch: draws the mode at once. The shared script then presses Show me (not under reduced motion), which plays it.
+ document.addEventListener('hb:mode',e=>{mode=e.detail.mode;draw()});
+ addEventListener('resize',draw);
+ if(document.fonts)document.fonts.ready.then(draw);
showPage(0);
</script>
+
</body>
</html>