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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Slide Up Reveal — Animation Handbook</title>
<meta name="description" content="Text rises into view from behind an invisible edge. Best for headlines.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/slide-up-reveal/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
<link rel="apple-touch-icon" href="../../../apple-touch-icon.png">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Slide Up Reveal — Animation Handbook">
<meta property="og:description" content="Text rises into view from behind an invisible edge. Best for headlines.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/slide-up-reveal/">
<meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Slide Up Reveal — Animation Handbook">
<meta name="twitter:description" content="Text rises into view from behind an invisible edge. Best for headlines.">
<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": "Slide Up Reveal", "name": "Slide Up Reveal", "description": "Text rises into view from behind an invisible edge. Best for headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/slide-up-reveal/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Slide Up Reveal"}</script>
<style>
:root{--ui-accent:#5fd88a;--ui-muted:#8a8a92;--dur:700ms;--ease:cubic-bezier(.2,.7,.3,1);--stagger:60ms}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;overflow:hidden;padding:clamp(20px,5vw,40px);background:#0b0b0d}
.line-wrap{overflow:hidden;line-height:1.15}
[data-method="translatey"] .line{display:block;transform:translateY(110%);transition:transform var(--dur) var(--ease);transition-delay:calc(var(--d,0)*var(--stagger))}
[data-method="translatey"] .line.in{transform:translateY(0)}
[data-method="clippath"] .line{display:block;clip-path:inset(100% 0 0 0);transition:clip-path var(--dur) var(--ease);transition-delay:calc(var(--d,0)*var(--stagger))}
[data-method="clippath"] .line.in{clip-path:inset(0% 0 0 0)}
.headline{font-size:clamp(28px,5vw,52px);font-weight:bold;text-align:center;line-height:1.1}
.sub-line{font-size:clamp(13px,2vw,16px);color:var(--ui-muted);text-align:center}
@media(prefers-reduced-motion:reduce){.line{opacity:0;transition:opacity 300ms linear!important;transform:none!important;clip-path:none!important} .line.in{opacity:1!important}}
/* See inside and Compare. The script wraps each window in a .slot with a faint copy of its line (.ghost) and an edge mark (.edge),
and makes the "No edge" half (.twin) once; all of it, and every caption, is hidden in Normal. */
.stage{position:relative}
.slot{position:relative;line-height:1.15}
.ghost,.edge,.twin,.lbl{display:none}
.lbl{position:absolute;left:0;top:0;z-index:3;width:max-content;max-width:var(--mw,none);padding:3px 7px;border-radius:5px;background:rgba(11,11,13,.92);color:#f4f4f2;font:600 13px/1.2 var(--hb-font);text-wrap:balance}
.lbl[hidden]{display:none!important}
.stage.posed .when{visibility:visible}
.when{visibility:hidden}
[data-method="translatey"] .ghost{transform:translateY(110%);transition:transform var(--dur) var(--ease);transition-delay:calc(var(--d,0)*var(--stagger))}
[data-method="translatey"] .ghost.in{transform:translateY(0)}
[data-method="clippath"] .edge{transform:translateY(100%);transition:transform var(--dur) var(--ease);transition-delay:calc(var(--d,0)*var(--stagger))}
[data-method="clippath"] .edge.in{transform:translateY(0)}
.stage[data-hb-mode="inside"],.stage[data-hb-mode="compare"]{padding:34px 8px}
.stage[data-hb-mode="inside"] .headline,.stage[data-hb-mode="compare"] .headline{font-size:var(--f,28px)}
.stage[data-hb-mode="inside"] .for-inside,.stage[data-hb-mode="inside"] .for-both,.stage[data-hb-mode="compare"] .for-compare,.stage[data-hb-mode="compare"] .for-both{display:block}
/* See inside: each line in its own outlined window with a gap under it as tall as the line, so the part under the edge has room */
.stage[data-hb-mode="inside"].narrow{align-items:flex-start;padding-left:12px}
.stage[data-hb-mode="inside"] .slot{margin-bottom:var(--gap,0)}
.stage[data-hb-mode="inside"] .line-wrap{position:relative;outline:1px solid color-mix(in srgb,var(--ui-accent) 75%,transparent);background:color-mix(in srgb,var(--ui-accent) 9%,transparent)}
.stage[data-hb-mode="inside"] .ghost{display:block;position:absolute;left:0;right:0;top:0;opacity:.34;pointer-events:none}
.stage[data-hb-mode="inside"] .edge{display:block;position:absolute;left:-8px;right:-8px;pointer-events:none}
.stage[data-hb-mode="inside"][data-method="translatey"] .edge{top:100%;height:2px;margin-top:-1px;background:var(--ui-accent)}
.stage[data-hb-mode="inside"][data-method="clippath"] .edge{top:0;bottom:0;border-top:2px solid var(--ui-accent)}
/* Compare: the lines twice, "No edge" (windows that do not clip) beside "Behind an edge" (the real ones) */
.stage[data-hb-mode="compare"]{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));align-items:center;justify-items:center;gap:0}
.stage[data-hb-mode="compare"]::after{content:"";position:absolute;left:50%;top:34px;bottom:34px;width:1px;background:rgba(255,255,255,.16)}
.stage[data-hb-mode="compare"] .twin{display:block}
.stage[data-hb-mode="compare"] .twin .line-wrap{overflow:visible}
.stage[data-hb-mode="compare"] .twin .line{clip-path:none!important}
.stage[data-hb-mode="compare"] #lines-wrap .edge{display:block;position:absolute;left:0;right:0;opacity:.6;pointer-events:none}
.stage[data-hb-mode="compare"][data-method="translatey"] #lines-wrap .edge{top:100%;height:1px;background:var(--ui-accent)}
.stage[data-hb-mode="compare"][data-method="clippath"] #lines-wrap .edge{top:0;bottom:0;border-top:1px solid var(--ui-accent)}
/* The rest pose, a fifth of a second into the reveal: each line at its own share (--p), beating .line.in and the reduced motion rules */
.stage[data-hb-mode="inside"].posed .line,.stage[data-hb-mode="compare"].posed .line{opacity:1!important;transition:none!important}
.stage[data-hb-mode="inside"].posed :is(.ghost,.edge),.stage[data-hb-mode="compare"].posed .edge{transition:none!important}
.stage[data-hb-mode="inside"].posed[data-method="translatey"] :is(.line,.ghost),.stage[data-hb-mode="compare"].posed[data-method="translatey"] .line{transform:translateY(calc((1 - var(--p))*110%))!important}
.stage[data-hb-mode="inside"].posed[data-method="clippath"] .line,.stage[data-hb-mode="compare"].posed[data-method="clippath"] #lines-wrap .line{clip-path:inset(calc((1 - var(--p))*100%) 0 0 0)!important}
.stage[data-hb-mode="inside"].posed[data-method="clippath"] .edge,.stage[data-hb-mode="compare"].posed[data-method="clippath"] #lines-wrap .edge{transform:translateY(calc((1 - var(--p))*100%))!important}
@media(max-width:600px){.lbl{padding:2px 5px}}
@media(max-width:600px),(max-height:500px){.stage[data-hb-mode="inside"] .t-late{display:none}}
@media(prefers-reduced-motion:reduce){.ghost,.edge{transition:none!important}}
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=11">
<script src="../../../assets/js/demo-page.js?v=11" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
<a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
<span class="hb-pager"><a href="../slide-in/" rel="prev" aria-label="Previous: Slide In"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Slide In</span></a><a href="../scale-in/" rel="next" aria-label="Next: Scale In / Zoom In"><span><span class="hb-dir">Next: </span>Scale In / Zoom In</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
<a class="hb-star" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener" aria-label="Star on GitHub"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg><span>Star on GitHub</span></a>
</nav>
<main class="hb-page">
<header class="hb-head">
<p class="hb-cat">02.03 · Entrance & Exit</p>
<h1>Slide Up Reveal</h1>
<p class="hb-lede">Text rises into view from behind an invisible edge. Best for headlines.</p>
</header>
<section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
<div class="hb-step-head">
<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" id="stage" data-method="translatey">
<div id="lines-wrap">
<div class="line-wrap"><span class="headline line" id="l0" style="--d:0">Beautiful</span></div>
<div class="line-wrap"><span class="headline line" id="l1" style="--d:1">interfaces</span></div>
<div class="line-wrap"><span class="sub-line line" id="l2" style="--d:2">crafted with care.</span></div>
</div>
<p class="lbl for-inside t-edge" data-hb-caption aria-hidden="true">The edge: nothing shows below it</p>
<p class="lbl for-inside t-hid" data-hb-caption aria-hidden="true">Still hidden, already there</p>
<p class="lbl for-inside t-move" data-hb-caption aria-hidden="true">Each line rises from behind its edge</p>
<p class="lbl for-inside t-late" data-hb-caption aria-hidden="true">Each line starts a moment after the one above</p>
<p class="lbl for-compare t-first" data-hb-caption aria-hidden="true">No edge</p>
<p class="lbl for-compare t-second" data-hb-caption aria-hidden="true">Behind an edge</p>
<p class="lbl for-both when" data-hb-caption aria-hidden="true">A fifth of a second in</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 line sits in its own window: below the window's edge nothing shows. The faint part is the line still hidden under the edge as it rises.</p>
<p data-hb-for="compare" hidden>No edge: you see each line travel up from below. Behind an edge: each line is cut off until it rises into view, so it seems to come from behind a surface.</p>
</div>
</section>
<section class="hb-step hb-try" aria-labelledby="hb-try-title">
<div class="hb-step-head">
<span class="hb-num" aria-hidden="true">2</span>
<div><h2 id="hb-try-title">Try it</h2><p>Change a setting and the animation plays again.</p></div>
</div>
<div class="hb-settings">
<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="1100" aria-pressed="false">Slow</button>
<button type="button" data-ms="700" class="on" aria-pressed="true">Normal</button>
<button type="button" data-ms="400" aria-pressed="false">Fast</button>
</div>
<p class="hb-hint">How long each line takes to rise.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="stagger-lbl">Delay between lines</p>
<div class="seg" id="stagger-seg" role="group" aria-labelledby="stagger-lbl">
<button type="button" data-stagger="30" aria-pressed="false">Short</button>
<button type="button" data-stagger="60" class="on" aria-pressed="true">Medium</button>
<button type="button" data-stagger="120" aria-pressed="false">Long</button>
</div>
<p class="hb-hint">Longer delays make the cascade easier to see.</p>
</div>
</div>
<details class="hb-options">
<summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
<div class="hb-settings">
<div class="hb-setting">
<p class="hb-setting-name" id="method-lbl">Reveal style</p>
<div class="seg" id="method-seg" role="group" aria-labelledby="method-lbl">
<button type="button" data-method="translatey" class="on" aria-pressed="true">Slide</button>
<button type="button" data-method="clippath" aria-pressed="false">Wipe</button>
</div>
<p class="hb-hint">Slide moves the text up; Wipe uncovers it in place.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="feel-lbl">Feel</p>
<div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">
<button type="button" data-ease="cubic-bezier(.2,.7,.3,1)" class="on" aria-pressed="true">Smooth</button>
<button type="button" data-ease="cubic-bezier(.34,1.56,.64,1)" aria-pressed="false">Springy</button>
<button type="button" data-ease="linear" aria-pressed="false">Even</button>
</div>
<p class="hb-hint">Springy goes a little past, then settles.</p>
</div>
</div>
</details>
</section>
<section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
<div class="hb-step-head">
<span class="hb-num" aria-hidden="true">3</span>
<div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
</div>
<div class="hb-card">
<p class="hb-prompt">Add a slide-up reveal to [your headline or lines of text]. Each line should rise into view from just below an invisible edge, as if it is coming up from behind a solid surface, so viewers only see it arrive and never see it below the line. The text can slide up behind the edge or be uncovered in place from the bottom up; both look almost the same. When there are several lines, start each one a moment after the line above it so they cascade. The text must stay readable by screen readers and search engines the whole time. If the visitor has reduced motion turned on, show the text immediately without the rise. Match the settings listed below.</p>
<div class="hb-chips-box" hidden>
<p class="hb-chips-title">Your settings</p>
<ul class="hb-chips"></ul>
</div>
<div class="hb-copy-row">
<button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
<p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
</div>
</div>
<div class="hb-star-row"><p>Free and open source. If this helped, a star on GitHub helps other people find it.</p><a class="hb-star-btn" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>Star on GitHub</a></div>
</section>
<section class="hb-about" aria-labelledby="hb-what-title">
<div class="hb-what">
<h2 id="hb-what-title">What it is</h2>
<div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
</div>
<div class="hb-fit">
<h2>Good for</h2>
<ul class="hb-tags hb-good"><li>Headlines</li><li>Section titles</li><li>Taglines</li></ul>
<h3>Avoid on</h3>
<ul class="hb-tags hb-avoid"><li>Long paragraphs</li><li>Buttons</li></ul>
</div>
</section>
<section class="hb-related" aria-labelledby="hb-related-title" hidden>
<h2 id="hb-related-title">Similar animations</h2>
<div class="hb-rel-list"></div>
</section>
</main>
<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 stage=document.getElementById('stage');
const lines=[...document.querySelectorAll('.line')];
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;
let ms=700,stagger=60,ease='cubic-bezier(.2,.7,.3,1)',timers=[],restTimer=0;
// See inside and Compare. Copies are made once, out of reach of the keyboard and screen readers: "No edge" (Compare's first half:
// the three lines again, with windows that do not clip), and for each window a faint copy of its line that is never clipped
// (.ghost) and an edge mark (.edge). Each window sits in a .slot that holds them; Normal does not show any of it.
const linesWrap=document.getElementById('lines-wrap');
const twin=linesWrap.cloneNode(true);
twin.removeAttribute('id');twin.classList.add('twin');twin.inert=true;twin.setAttribute('aria-hidden','true');
twin.querySelectorAll('[id]').forEach(e=>e.removeAttribute('id'));
linesWrap.before(twin);
const parts=lines.map((l,i)=>{
const slot=document.createElement('div'),ghost=l.cloneNode(true),edge=document.createElement('span'),win=l.parentElement;
slot.className='slot';
ghost.removeAttribute('id');ghost.classList.replace('line','ghost');ghost.inert=true;ghost.setAttribute('aria-hidden','true');
edge.className='edge';edge.style.setProperty('--d',i);edge.setAttribute('aria-hidden','true');
win.before(slot);slot.append(ghost,win,edge);
return {win,slot,ghost,edge,twin:twin.querySelectorAll('.line')[i]};
});
const all=[...lines,...parts.flatMap(p=>[p.ghost,p.edge,p.twin])];
// The rest pose is a fifth of a second into the reveal; the band, gutters and ticks are in pixels
const POSE_MS=200,BAND=34,PAD=8,TICK=14;
const NOTES={
slide:{inside:document.querySelector('[data-hb-for="inside"]').textContent,compare:document.querySelector('[data-hb-for="compare"]').textContent},
wipe:{inside:"Inside, each line stays still in its own window, and the window's edge opens upward. The faint part is the line still hidden.",
compare:'With Wipe nothing moves: No edge shows the text at once, and Behind an edge uncovers each line from the bottom up.'},
slideStill:{inside:'Shown still, a fifth of a second in: each line sits in its own window, and the faint part is the line still hidden under its edge.',
compare:'Shown still, a fifth of a second in: No edge shows each line below its place, while Behind an edge cuts each one off at its edge.'},
wipeStill:{inside:'Shown still, a fifth of a second in: each line stays still in its own window, and the faint part is still hidden above the opening edge.',
compare:'Shown still, a fifth of a second in: No edge shows the text whole, while Behind an edge has uncovered only the bottom of each line.'}
};
const WORDS={slide:{edge:'The edge: nothing shows below it',move:'Each line rises from behind its edge'},
wipe:{edge:'The opening edge: nothing shows above it',move:'The text stays still; its edge opens upward'}};
const L=n=>stage.querySelector('.'+n);
const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
let mode='normal',EM=5.2;
function dur(){return slowTog.checked?ms*3:ms}
function stag(){return slowTog.checked?stagger*3:stagger}
function apply(){
vars.setProperty('--dur',dur()+'ms');
vars.setProperty('--stagger',stag()+'ms');
vars.setProperty('--ease',ease);
}
function later(fn,wait){timers.push(setTimeout(fn,wait))}
function setIn(on){all.forEach(el=>el.classList.toggle('in',on))}
function revealIn(){
// snap back to hidden without a transition so every play rises from behind the edge again
all.forEach(l=>l.style.setProperty('transition','none','important'));
setIn(false);
void stage.offsetWidth;
all.forEach(l=>l.style.removeProperty('transition'));
setIn(true);
}
// One play reveals the lines. While Loop is on it then holds, drops the lines back down, waits and plays again;
// switching Loop off lets the lines finish risen. Slow motion stretches the reveal and the stagger, not the waits.
function cycle(){
clearTimeout(restTimer);apply();pose(false);revealIn();
if(!loopTog.checked||!motionOk){restLater();return}
later(()=>{
if(!loopTog.checked)return;
setIn(false);
later(cycle,dur()+400);
},dur()+1000);
}
function play(){timers.forEach(clearTimeout);timers=[];cycle()}
// The value of a speed curve at a share x of its time: the curve's own t for x found by halving, then its height there
function curveAt([a,b,c,e],x){
const at=(p,q,t)=>3*p*t*(1-t)*(1-t)+3*q*t*t*(1-t)+t*t*t;
let lo=0,hi=1,t=x;
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);
}
// How far line i has come a fifth of a second in: its own delay first, the same Speed and Feel (Slow motion does not move a rest pose)
function share(i){return curveAt(ease==='linear'?[0,0,1,1]:ease.match(/[\d.]+/g).map(Number),clamp((POSE_MS-i*stagger)/ms,0,1))}
// The still moment both views rest on between plays (Loop off, and always under reduced motion), set again for every deal
function pose(on){
on=on&&mode!=='normal';
stage.classList.toggle('posed',on);
if(on)parts.forEach((p,i)=>[lines[i],p.ghost,p.edge,p.twin].forEach(el=>el.style.setProperty('--p',share(i).toFixed(3))));
}
// Leaving the still moment shows the lines as they now are, at once; a play under way is left alone
function unpose(){
if(!stage.classList.contains('posed'))return;
all.forEach(el=>el.style.setProperty('transition','none','important'));
pose(false);void stage.offsetWidth;
all.forEach(el=>el.style.removeProperty('transition'));
}
// With Loop off a view goes back to its still moment once the lines have risen and been seen for a moment
function restLater(){clearTimeout(restTimer);restTimer=setTimeout(()=>pose(true),(motionOk?dur():300)+2*stag()+700)}
function say(el,text){if(el.textContent!==text)el.textContent=text}
function words(){
const m=stage.dataset.method==='clippath'?'wipe':'slide',n=NOTES[m+(motionOk?'':'Still')];
say(document.querySelector('[data-hb-for="inside"]'),n.inside);say(document.querySelector('[data-hb-for="compare"]'),n.compare);
say(L('t-edge'),WORDS[m].edge);say(L('t-move'),WORDS[m].move);
}
// The box's own pixels: the headline is fitted to the box (to the room left for the side captions in See inside, to half the
// width in Compare), the gap under each window is its line's height, and each caption is placed from its measured size.
function layout(){
if(mode==='normal')return;
const W=stage.clientWidth,H=stage.clientHeight,inside=mode==='inside',wipe=stage.dataset.method==='clippath';
const s=parseFloat(getComputedStyle(lines[2]).fontSize),r=document.createRange();
r.selectNodeContents(lines[1]);
EM=r.getBoundingClientRect().width/parseFloat(getComputedStyle(lines[1]).fontSize)||EM;
// a narrow box keeps the lines to the left and both side captions to their right
const narrow=inside&&W<500,gut=clamp((W-130)/2,80,111);
stage.classList.toggle('narrow',narrow);
const f=Math.floor(clamp(Math.min(inside?52:clamp(innerWidth*.05,28,52),inside?(narrow?W-12-gut:W-2*gut)/EM:(W/2-2*PAD-4)/EM,
inside?(H-2*BAND-2.3*s-8)/4.4:(H-2*BAND-1.15*s-8)/3.4),20,52));
stage.style.setProperty('--f',f+'px');
parts.forEach(p=>p.slot.style.setProperty('--gap',p.win.offsetHeight+'px'));
const O=stage.getBoundingClientRect(),
box=el=>{const b=el.getBoundingClientRect();return{l:b.left-O.left-stage.clientLeft,r:b.right-O.left-stage.clientLeft,t:b.top-O.top-stage.clientTop,b:b.bottom-O.top-stage.clientTop}};
const put=(el,cap,x,y,lo=4,hi=H-4)=>{
el.style.setProperty('--mw',cap+'px');el.style.left='0';el.style.top='0';
const w=el.offsetWidth,h=el.offsetHeight;
el.style.left=clamp(x(w),4,W-w-4)+'px';el.style.top=clamp(y(h),lo,hi-h)+'px';
};
put(L('when'),W-16,w=>(W-w)/2,h=>H-h-8);
if(!inside){
put(L('t-first'),W/2-12,w=>W/4-w/2,()=>8);put(L('t-second'),W/2-12,w=>3*W/4-w/2,()=>8);
return;
}
const k=parts.map(p=>box(p.win)),h0=k[0].b-k[0].t,h1=k[1].b-k[1].t;
// the edge: Slide's is the window's bottom; Wipe's is where the first line's still moment has opened it. The second line's hidden part:
// below its window (Slide) or above its opening edge (Wipe)
const ey=wipe?k[0].t+Math.max(1-share(0),0)*h0:k[0].b,hy=wipe?k[1].t+Math.max(1-share(1),.2)*h1/2:k[1].b+.55*Math.max(1-share(1),.1)*h1;
// the side captions keep between the top caption and the bottom one
const top=L('t-move');put(top,W-16,w=>(W-w)/2,()=>8);
const lo=top.offsetTop+top.offsetHeight+4,hi=L('when').offsetTop-4;
put(L('t-edge'),W-k[0].r-TICK-6,()=>k[0].r+TICK,h=>ey-h/2,lo,hi);
if(narrow)put(L('t-hid'),W-k[0].r-TICK-6,()=>k[0].r+TICK,h=>hy-h/2,Math.max(lo,L('t-edge').offsetTop+L('t-edge').offsetHeight+4),hi);
else put(L('t-hid'),k[0].l-TICK-6,w=>k[0].l-TICK-w,h=>hy-h/2,lo,hi);
const late=L('t-late');
put(late,W-k[0].r-TICK-6,()=>k[0].r+TICK,h=>(k[1].t+k[1].b)/2-h/2,lo,hi);
const a=late.getBoundingClientRect(),b=L('t-edge').getBoundingClientRect();
late.hidden=a.top<b.bottom+6&&a.bottom>b.top-6;
}
function refresh(){
if(stage.classList.contains('posed'))pose(true);
words();layout();
}
// The mode switch: draws the mode at once, never plays. The shared script then presses Replay (not under reduced motion).
document.addEventListener('hb:mode',e=>{
mode=e.detail.mode;
if(mode==='normal')unpose();else pose(!(loopTog.checked&&motionOk));
refresh();
});
new ResizeObserver(layout).observe(stage);
document.fonts.ready.then(layout);
document.getElementById('btn-play').addEventListener('click',play);
loopTog.addEventListener('change',()=>{if(loopTog.checked)play();else restLater()});
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);
refresh();
}));
}
choices('speed-seg',d=>{ms=+d.ms});
choices('stagger-seg',d=>{stagger=+d.stagger});
choices('method-seg',d=>{stage.dataset.method=d.method});
choices('feel-seg',d=>{ease=d.ease});
words();
apply();
</script>
</body>
</html>