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>Scanline Effect — Animation Handbook</title>
<meta name="description" content="Dark lines and a sweeping beam imitate an old TV screen. Best for retro sites.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/scanline/">
<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="Scanline Effect — Animation Handbook">
<meta property="og:description" content="Dark lines and a sweeping beam imitate an old TV screen. Best for retro sites.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/scanline/">
<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="Scanline Effect — Animation Handbook">
<meta name="twitter:description" content="Dark lines and a sweeping beam imitate an old TV screen. Best for retro sites.">
<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": "Scanline Effect", "name": "Scanline Effect", "description": "Dark lines and a sweeping beam imitate an old TV screen. Best for retro sites.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/scanline/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Scanline Effect"}</script>
<style>
:root{--ui-accent:#ffce5a;--line-gap:4px;--line-dark:.15;--beam-dur:4s;--beam-bright:.12}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{position:relative;overflow:hidden;background:#05080d}
/* Screen content */
.screen-content{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:32px}
.terminal{width:100%;max-width:420px;background:#040608;border:1px solid rgba(88,166,255,.2);border-radius:6px;padding:20px 24px}
.term-bar{display:flex;gap:6px;margin-bottom:14px}
.dot{width:10px;height:10px;border-radius:50%}
.dot.r{background:#f85149}.dot.y{background:#ffa657}.dot.g{background:#56d364}
.term-line{font-size:clamp(12px,1.4vw,14px);color:#58a6ff;line-height:1.7;opacity:.9}
.term-line.dim{opacity:.75}
.term-cursor{display:inline-block;width:8px;height:1em;background:#58a6ff;vertical-align:text-bottom;animation:blink 1s step-end infinite}
@keyframes blink{50%{opacity:0}}
/* Scanline overlay */
.scanlines{
position:absolute;inset:0;pointer-events:none;z-index:5;
background:repeating-linear-gradient(
to bottom,
transparent 0px,
transparent calc(var(--line-gap) - 1px),
rgba(0,0,0,var(--line-dark)) calc(var(--line-gap) - 1px),
rgba(0,0,0,var(--line-dark)) var(--line-gap)
)
}
/* Sweep beam */
.beam{
/* Element is 120px taller than the stage; the 120px band sits at its top
edge, so translateY(0 → 100%) sweeps the band across and off the stage. */
position:absolute;left:0;right:0;top:-120px;height:calc(100% + 120px);z-index:6;pointer-events:none;
background:linear-gradient(to bottom,transparent 0%,rgba(255,255,255,var(--beam-bright)) 50%,transparent 100%);
background-size:100% 120px;background-repeat:no-repeat;background-position:0 0;
animation:beam-sweep var(--beam-dur) linear infinite;
/* Starts 40% into the first sweep, so the band is on the screen at once, even in the still frame of a paused stage */
animation-delay:calc(var(--beam-dur) * -.4);
will-change:transform
}
@keyframes beam-sweep{from{transform:translateY(0)}to{transform:translateY(100%)}}
/* Dark corners — radial vignette darkening the corners */
.crt-wrap{position:absolute;inset:0;pointer-events:none;display:none}
.crt-inner{position:absolute;inset:-5%;background:radial-gradient(ellipse at center,transparent 60%,rgba(0,0,0,.5) 100%)}
/* Glowing text (via CSS on terminal) */
.phosphor .term-line{text-shadow:0 0 8px #58a6ff,0 0 20px rgba(88,166,255,.3)}
/* See inside and Compare: every rule here names one of them, so Normal is drawn as it always was. The wrapper around the beam
only stands in for it (it draws nothing in Normal); the views reuse the page's own layers, so every setting reaches them. */
.beam-card{display:contents}
.band-start,.cap,.side,.sweep-arrow,.copy{display:none}
.cap,.side{position:absolute;z-index:8;padding:3px 8px;border-radius:5px;background:rgba(8,8,10,.9);color:#f4f4f2;font:600 13px/1.2 var(--hb-font)}
/* See inside: the layers pulled apart into cards at two fifths of the box, fanned from the top left (the screen, at the back)
to the bottom right (the front), in the order they lie in Normal. The script gives each shown card its place along the
fan (--f, 0 to 1) and the stage a margin for the arrow (--mr). A card is the layer itself, scaled and moved with scale and
translate (the beam's own animation keeps running), except the lines: their card is laid out at its size, so the lines
keep their real spacing instead of blurring into a gray wash. Captions are drawn at their size over the cards. */
.stage[data-hb-mode="inside"]{--m:8px;--mr:0px}
.stage[data-hb-mode="inside"] :is(.screen-content,.crt-wrap,.beam-card){scale:.4;translate:calc(var(--m) + var(--f,0) * (60% - 2 * var(--m) - var(--mr)) - 30%) calc(var(--m) + var(--f,0) * (60% - 2 * var(--m)) - 30%);outline:5px solid rgba(244,244,242,.6);outline-offset:-5px}
.stage[data-hb-mode="inside"] .screen-content{z-index:1;background:#0c131c;align-items:flex-end;padding-bottom:18px}
.stage[data-hb-mode="inside"] .crt-wrap{z-index:2;overflow:hidden;background:#7d848f}
.stage[data-hb-mode="inside"] .scanlines{z-index:3;inset:auto;width:40%;height:40%;left:calc(var(--m) + var(--f,0) * (60% - 2 * var(--m) - var(--mr)));
top:calc(var(--m) + var(--f,0) * (60% - 2 * var(--m)));top:round(calc(var(--m) + var(--f,0) * (60% - 2 * var(--m))),1px);background-color:#d3d7dd;outline:2px solid rgba(244,244,242,.6);outline-offset:-2px}
.stage[data-hb-mode="inside"] .beam-card{display:block;position:absolute;inset:0;z-index:4;overflow:hidden;background:#1f2733}
.stage[data-hb-mode="inside"] .beam-card.off{display:none}
/* Where each sweep starts: the band's own size at the top of its card (ruling 2: the sweep is drawn at card size), and an arrow
beside the card for its path */
.stage[data-hb-mode="inside"] .band-start{display:block;position:absolute;left:14px;right:14px;top:0;height:120px;z-index:7;
border:5px dashed rgba(244,244,242,.5);border-top:0}
.stage[data-hb-mode="inside"] :is(.cap-screen,.cap-corners,.cap-lines){left:calc(var(--m) + var(--f,0) * (60% - 2 * var(--m) - var(--mr)) + 6px);top:calc(var(--m) + var(--f,0) * (60% - 2 * var(--m)) + 6px);white-space:nowrap}
.stage[data-hb-mode="inside"] .cap-beam{right:calc(40% + var(--m) + var(--mr) + 6px);bottom:var(--m);max-width:calc(60% - var(--m) - var(--mr) - 14px)}
.stage[data-hb-mode="inside"] .cap:not([hidden]){display:block}
.stage[data-hb-mode="inside"] .sweep-arrow{position:absolute;z-index:8;right:14px;top:calc(60% - var(--m) + 6px);bottom:calc(var(--m) + 14px);width:2px;background:rgba(244,244,242,.7)}
.stage[data-hb-mode="inside"] .sweep-arrow:not([hidden]){display:block}
.stage[data-hb-mode="inside"] .sweep-arrow::after{content:"";position:absolute;left:-5px;bottom:-9px;border:6px solid transparent;border-top:9px solid rgba(244,244,242,.7);border-bottom:0}
.stage[data-hb-mode="inside"] .phosphor .term-line{text-shadow:0 0 16px #58a6ff,0 0 40px rgba(88,166,255,.45)}
/* Compare: the plain terminal on the left, the real screen with its lines, beam and corners on the right half. The layers keep
their rules and only move their left edge to the middle, so the beam's sweep carries on. Both scenes start under the names. */
.stage[data-hb-mode="compare"]{background:#142031}
.stage[data-hb-mode="compare"] .screen-content{top:38px;padding:6px}
.stage[data-hb-mode="compare"] .copy{display:flex;right:50%}
.stage[data-hb-mode="compare"] .screen-content:not(.copy){left:50%}
.stage[data-hb-mode="compare"] :is(.scanlines,.beam,.crt-wrap){left:50%}
.stage[data-hb-mode="compare"] .crt-wrap{overflow:hidden}
.stage[data-hb-mode="compare"] .terminal{padding:12px 12px 8px}
.stage[data-hb-mode="compare"] .term-bar{margin-bottom:8px}
.stage[data-hb-mode="compare"] .term-line{white-space:nowrap}
.stage[data-hb-mode="compare"]::after{content:"";position:absolute;top:0;bottom:0;left:50%;width:2px;margin-left:-1px;background:rgba(244,244,242,.35);z-index:7}
.stage[data-hb-mode="compare"] .side{display:block;top:8px}
.side-a{left:8px}.side-b{left:calc(50% + 8px)}
</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="loop">
<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="../grain-overlay/" rel="prev" aria-label="Previous: Grain / Film Noise Overlay"><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>Grain / Film Noise Overlay</span></a><a href="../light-leak/" rel="next" aria-label="Next: Light Leak"><span><span class="hb-dir">Next: </span>Light Leak</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">07.05 · Ambient & Background</p>
<h1>Scanline Effect</h1>
<p class="hb-lede">Dark lines and a sweeping beam imitate an old TV screen. Best for retro sites.</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 moves by itself. Pause it to look closely, or 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">
<div class="screen-content">
<div class="terminal" id="terminal">
<div class="term-bar" aria-hidden="true"><span class="dot r"></span><span class="dot y"></span><span class="dot g"></span></div>
<div class="term-line">SYSTEM READY</div>
<div class="term-line dim">Tuning the signal…</div>
<div class="term-line">All channels clear</div>
<div class="term-line dim">Picture steady</div>
<div class="term-line"><span class="term-cursor" aria-hidden="true"></span></div>
</div>
</div>
<div class="scanlines" aria-hidden="true"></div>
<div class="beam-card" aria-hidden="true">
<div class="beam" id="beam" aria-hidden="true"></div>
<div class="band-start"></div>
</div>
<div class="crt-wrap" id="crt-wrap" aria-hidden="true"><div class="crt-inner"></div></div>
<span class="cap cap-screen" data-hb-caption aria-hidden="true">The screen</span>
<span class="cap cap-corners" data-hb-caption aria-hidden="true" hidden>Dark corners</span>
<span class="cap cap-lines" data-hb-caption aria-hidden="true">Thin dark lines</span>
<span class="cap cap-beam" data-hb-caption aria-hidden="true">A band of light sweeps down every 4 seconds</span>
<i class="sweep-arrow" aria-hidden="true"></i>
<span class="side side-a" data-hb-caption aria-hidden="true">Plain screen</span>
<span class="side side-b" data-hb-caption aria-hidden="true">Scanlines</span>
</div>
<div class="hb-player">
<button class="hb-play" type="button" id="btn-pause" data-hb-pause="css" data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>
<label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo="css" autocomplete="off"><span>Slow motion</span></label>
</div>
<div class="hb-mode-notes" aria-live="polite">
<p data-hb-for="inside" hidden>Inside, the layers are pulled apart: the screen, a sheet of thin dark lines laid over it and a soft band of light that sweeps down again and again.</p>
<p data-hb-for="compare" hidden>Plain screen is the same terminal with nothing over it. Scanlines lays thin dark lines across it and sweeps a soft band of light down, like an old tube screen.</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 see the difference as it moves.</p></div>
</div>
<div class="hb-settings">
<div class="hb-setting">
<p class="hb-setting-name" id="gap-lbl">Line spacing</p>
<div class="seg" id="gap-seg" role="group" aria-labelledby="gap-lbl">
<button type="button" data-gap="2" aria-pressed="false">Tight</button>
<button type="button" data-gap="4" class="on" aria-pressed="true">Medium</button>
<button type="button" data-gap="8" aria-pressed="false">Wide</button>
</div>
<p class="hb-hint">Tight lines look most like a real old screen.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="dark-lbl">Line darkness</p>
<div class="seg" id="dark-seg" role="group" aria-labelledby="dark-lbl">
<button type="button" data-dark="0.08" aria-pressed="false">Light</button>
<button type="button" data-dark="0.15" class="on" aria-pressed="true">Medium</button>
<button type="button" data-dark="0.3" aria-pressed="false">Dark</button>
</div>
<p class="hb-hint">Darker lines look more retro but are harder to read.</p>
</div>
<div class="hb-setting">
<label class="hb-switch-row"><span>Moving beam</span><input class="hb-switch" type="checkbox" role="switch" id="beam-tog" checked autocomplete="off"></label>
<p class="hb-hint">A band of light sweeps down the screen.</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" id="speed-setting">
<p class="hb-setting-name" id="speed-lbl">Beam speed</p>
<div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
<button type="button" data-secs="6.4" aria-pressed="false">Slow</button>
<button type="button" data-secs="4" class="on" aria-pressed="true">Normal</button>
<button type="button" data-secs="2.4" aria-pressed="false">Fast</button>
</div>
<p class="hb-hint">How long the beam takes to cross the screen.</p>
</div>
<div class="hb-setting" id="bright-setting">
<p class="hb-setting-name" id="bright-lbl">Beam brightness</p>
<div class="seg" id="bright-seg" role="group" aria-labelledby="bright-lbl">
<button type="button" data-bright="0.06" aria-pressed="false">Faint</button>
<button type="button" data-bright="0.12" class="on" aria-pressed="true">Medium</button>
<button type="button" data-bright="0.24" aria-pressed="false">Bright</button>
</div>
<p class="hb-hint">Keep the beam faint: it should be felt, not seen.</p>
</div>
<div class="hb-setting">
<label class="hb-switch-row"><span>Dark corners</span><input class="hb-switch" type="checkbox" role="switch" id="crt-tog" autocomplete="off"></label>
<p class="hb-hint">Darkens the corners like an old screen's curved glass.</p>
</div>
<div class="hb-setting">
<label class="hb-switch-row"><span>Glowing text</span><input class="hb-switch" type="checkbox" role="switch" id="glow-tog" autocomplete="off"></label>
<p class="hb-hint">A soft glow around the letters.</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 scanline effect to [the screen, panel or section you want to look like an old monitor]. Lay thin, dark horizontal lines over the content with a repeating stripe pattern, in a layer that clicks pass through, so it looks like the rows of an old tube screen. When the settings include them, sweep a soft band of light slowly down the screen again and again, darken the corners like curved glass, and give the text a soft glow. Make sure the text stays readable through the lines. If the visitor has reduced motion turned on, keep the beam still. 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>Retro and gaming sites</li><li>Terminal screens</li><li>Music players</li><li>Sci-fi interfaces</li></ul>
<h3>Avoid on</h3>
<ul class="hb-tags hb-avoid"><li>Long reading</li><li>Forms</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 beam=document.getElementById('beam');
const beamTog=document.getElementById('beam-tog');
const beamOnly=[document.getElementById('speed-setting'),document.getElementById('bright-setting')];
const vars=document.documentElement.style;
let beamSecs=4;
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);
}));
}
choices('gap-seg',d=>{vars.setProperty('--line-gap',d.gap+'px')});
choices('dark-seg',d=>{vars.setProperty('--line-dark',d.dark)});
// A new --beam-dur keeps the time the beam has already swept, so it would jump to another point of its sweep.
// Scaling that time by the same factor as the sweep keeps the beam where it is, moving or paused
// (its start offset is a share of the sweep, so it scales too).
choices('speed-seg',d=>{
const next=+d.secs;
beam.getAnimations().forEach(a=>{if(a.currentTime!=null)a.currentTime=a.currentTime*next/beamSecs});
beamSecs=next;
vars.setProperty('--beam-dur',next+'s');
});
choices('bright-seg',d=>{vars.setProperty('--beam-bright',d.bright)});
// The beam's own settings only matter while the beam is showing
beamTog.addEventListener('change',()=>{
beam.style.display=beamTog.checked?'block':'none';
beamOnly.forEach(s=>{s.hidden=!beamTog.checked});
});
document.getElementById('crt-tog').addEventListener('change',e=>{
document.getElementById('crt-wrap').style.display=e.target.checked?'block':'none';
});
document.getElementById('glow-tog').addEventListener('change',e=>{
document.getElementById('terminal').classList.toggle('phosphor',e.target.checked);
});
// See inside and Compare. The listener for the mode switch comes first and the rest follows it.
const stage=document.querySelector('.stage'),scene=stage.querySelector('.screen-content');
const beamCard=beam.parentElement,crt=document.getElementById('crt-wrap'),lines=stage.querySelector('.scanlines');
const crtTog=document.getElementById('crt-tog'),slowTog=document.getElementById('slow-tog'),arrow=stage.querySelector('.sweep-arrow');
const cap={screen:stage.querySelector('.cap-screen'),corners:stage.querySelector('.cap-corners'),lines:stage.querySelector('.cap-lines'),beam:stage.querySelector('.cap-beam')};
const reduceMQ=matchMedia('(prefers-reduced-motion: reduce)');
let mode='normal',paused=reduceMQ.matches,posed=true;
document.addEventListener('hb:pause',e=>{paused=e.detail.paused;if(!paused)posed=false;describe()});
document.addEventListener('hb:mode',e=>{
mode=e.detail.mode;
layout();sweepWords();
if(mode==='compare')syncBlink();
if(mode!=='normal')poseBeam();
describe();
});
reduceMQ.addEventListener('change',()=>{if(mode!=='normal')poseBeam();describe()});
// Compare's plain half: a copy of the terminal made once, without its id, inert and hidden from screen readers. It never gets
// the glow, which belongs to the effect.
const copy=scene.cloneNode(true);
copy.classList.add('copy');copy.inert=true;copy.setAttribute('aria-hidden','true');
copy.querySelectorAll('[id]').forEach(el=>el.removeAttribute('id'));
scene.before(copy);
// The copy's cursor starts blinking when Compare first shows it: it takes the real cursor's time, so both blink together.
function syncBlink(){
const real=scene.querySelector('.term-cursor').getAnimations()[0],twin=copy.querySelector('.term-cursor').getAnimations()[0];
if(real&&twin&&real.currentTime!=null)twin.currentTime=real.currentTime;
}
// The cards fan out in the order the layers lie in Normal: the screen, the corners, the lines, the beam. Each shown card (and
// its caption) gets its place along the fan, and the stage a margin on the right for the beam's arrow.
function layout(){
const beamOn=beamTog.checked,cornersOn=crtTog.checked,parts=[[scene,cap.screen]];
if(cornersOn)parts.push([crt,cap.corners]);
parts.push([lines,cap.lines]);
if(beamOn)parts.push([beamCard,null]);
parts.forEach(([card,label],i)=>{
card.style.setProperty('--f',i/(parts.length-1));
if(label)label.style.setProperty('--f',i/(parts.length-1));
});
cap.corners.hidden=!cornersOn;cap.beam.hidden=arrow.hidden=!beamOn;
beamCard.classList.toggle('off',!beamOn);
stage.style.setProperty('--mr',beamOn?'22px':'0px');
}
// The beam's caption says how long a sweep takes now: Beam speed, three times as long in slow motion
function sweepWords(){
const words='A band of light sweeps down every '+ +(beamSecs*(slowTog.checked?3:1)).toFixed(1)+' seconds';
if(cap.beam.textContent!==words)cap.beam.textContent=words;
}
// Under reduced motion the loop rests wherever it was paused, perhaps with the band out of sight: a mode shows the band at
// the point of its sweep where the page starts it, on screen
function poseBeam(){
const a=reduceMQ.matches&&paused&&beam.getAnimations()[0];
if(a){a.currentTime=0;posed=true}
}
// The notes: the markup holds the words for a moving band; these are the others. The still ones show only while the loop is
// paused under reduced motion (and, with the band, only while it stands where a mode posed it), and a note is written only when
// its words change, as its box is read out loud.
const notes={inside:document.querySelector('[data-hb-for="inside"]'),compare:document.querySelector('[data-hb-for="compare"]')};
const WORDS={
inside:{
moving:notes.inside.textContent,
still:'Inside, the layers are pulled apart and shown still: the screen, a sheet of thin dark lines and a band of light; the arrow shows its sweep.',
plain:'Inside, the layers are pulled apart: the screen and a sheet of thin dark lines laid over it, like the rows of an old tube screen.',
plainStill:'Inside, the layers are pulled apart and shown still: the screen and a sheet of thin dark lines laid over it.'},
compare:{
moving:notes.compare.textContent,
still:'Plain screen is the same terminal with nothing over it. Scanlines, shown still, lays thin dark lines across it, with a soft band of light part way down.',
plain:'Plain screen is the same terminal with nothing over it. Scanlines lays thin dark lines across it, like the rows of an old tube screen.'}
};
WORDS.compare.plainStill=WORDS.compare.plain;
function describe(){
const still=reduceMQ.matches&&paused;
for(const k in notes){
const w=WORDS[k],words=beamTog.checked?(still&&posed?w.still:w.moving):(still?w.plainStill:w.plain);
if(notes[k].textContent!==words)notes[k].textContent=words;
}
}
beamTog.addEventListener('change',()=>{
if(beamTog.checked&&paused)posed=true; // a beam shown anew starts where the page starts it
layout();sweepWords();describe();
});
crtTog.addEventListener('change',layout);
slowTog.addEventListener('change',sweepWords);
document.querySelectorAll('#speed-seg button').forEach(b=>b.addEventListener('click',sweepWords));
layout();sweepWords();describe();
</script>
</body>
</html>