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>Marquee / Ticker — Animation Handbook</title>
<meta name="description" content="Text scrolls sideways in an endless loop, with no seam. Best for news tickers.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/marquee-ticker/">
<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="Marquee / Ticker — Animation Handbook">
<meta property="og:description" content="Text scrolls sideways in an endless loop, with no seam. Best for news tickers.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/marquee-ticker/">
<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="Marquee / Ticker — Animation Handbook">
<meta name="twitter:description" content="Text scrolls sideways in an endless loop, with no seam. Best for news tickers.">
<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": "Marquee / Ticker", "name": "Marquee / Ticker", "description": "Text scrolls sideways in an endless loop, with no seam. Best for news tickers.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/marquee-ticker/", "inLanguage": "en", "articleSection": "Text & Typography", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Text & Typography, Marquee / Ticker"}</script>
<style>
:root{--ui-accent:#ff6f8b;--marq-size:48px;--marq-gap:48px}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{position:relative;display:flex;flex-direction:column;justify-content:center;background:#08080a}
.marq-row{overflow:hidden;padding:16px 0;border-bottom:1px solid rgba(255,255,255,.09)}
.marq-row:last-child{border-bottom:none}
.marq-row.accent{background:rgba(255,111,139,.05)}
.marq-track{display:flex;width:max-content;white-space:nowrap;animation:marqL linear infinite}
.marq-track.rev{animation-name:marqR}
@media(hover:hover){.marq-row:hover .marq-track{animation-play-state:paused}}
.marq-row.paused .marq-track{animation-play-state:paused}
@keyframes marqL{from{transform:translateX(0)}to{transform:translateX(-50%)}}
@keyframes marqR{from{transform:translateX(-50%)}to{transform:translateX(0)}}
.marq-item{font-size:var(--marq-size);font-weight:700;line-height:1;color:#fff;padding:0 var(--marq-gap);display:flex;align-items:center;gap:var(--marq-gap)}
.marq-item.rev-row{color:rgba(255,255,255,.6)}
.sep{color:var(--ui-accent);font-size:.6em;opacity:.7}
/* The rows sit in a box of their own, laid out as the stage lays them out */
.rows{display:flex;flex-direction:column}
.zoom,.solo,.lbl{display:none}
.lbl{position:absolute;padding:3px 7px;border-radius:5px;background:rgba(8,8,10,.9);color:#f4f4f2;font:600 13px/1.2 var(--hb-font);white-space:nowrap}
/* In See inside and Compare the second and third rows stay where they were, unseen and out of the flow but never removed, so
their movement goes on for Normal */
.stage[data-hb-mode="inside"],.stage[data-hb-mode="compare"]{justify-content:flex-start}
.stage[data-hb-mode="inside"] .rows .marq-row:not(.r1),.stage[data-hb-mode="compare"] .rows .marq-row:not(.r1){position:absolute;left:0;right:0;visibility:hidden}
/* See inside: the first row at the top, still moving; below it the same strip zoomed out: its two identical copies end to end,
and the box as a window sliding over them. When the window reaches the second copy it jumps back to the first, which looks
the same, so the jump never shows. */
.stage[data-hb-mode="inside"] .zoom{display:flex;flex-direction:column}
.stage[data-hb-mode="inside"] .zoom .lbl{display:block}
/* The drawing sits in the middle of the room under the row (the side margins are the ones the script measures with) */
.zoom{position:relative;flex:1;margin:10px clamp(10px,2%,20px)}
.zin{position:relative;flex:none;margin:auto 0}
.ztrack{position:absolute;left:0;display:flex;width:max-content;white-space:nowrap;transform-origin:0 0}
/* the marks between the repeats drawn twice as big as the zoom makes them, so the Separator setting still shows */
.ztrack .sep{transform:scale(2)}
.zcopy{position:absolute;border:2px solid rgba(244,244,242,.6);border-radius:6px}
.zwin{position:absolute;left:0;border:3px solid var(--ui-accent);border-radius:6px;animation:zwin linear infinite}
@keyframes zwin{from{transform:translateX(0)}to{transform:translateX(var(--zgo,0px))}}
.zwin .lbl{left:0;top:calc(100% + 6px)}
.zjump{position:absolute;width:2px;background:#f4f4f2}
/* The arrow as long as the slide: a bar and a head whose tip is where the second copy starts */
.zarrow{position:absolute;left:0;height:13px}
.zarrow::before{content:"";position:absolute;left:0;right:9px;top:5px;height:3px;border-radius:2px;background:var(--ui-accent)}
.zarrow::after{content:"";position:absolute;right:0;top:0;border-style:solid;border-width:6.5px 0 6.5px 10px;border-color:transparent transparent transparent var(--ui-accent)}
.zback{transform:translateX(-50%)}
/* Pointing at the first row, or tapping it on a touch screen, stops the window in See inside and the one copy in Compare too */
@media(hover:hover){.stage[data-hb-mode="inside"]:has(.r1:hover) .zwin,.stage[data-hb-mode="compare"]:has(.r1:hover) .solo-track{animation-play-state:paused}}
.stage[data-hb-mode="inside"]:has(.r1.paused) .zwin,.stage[data-hb-mode="compare"]:has(.r1.paused) .solo-track{animation-play-state:paused}
/* Compare: on top the common mistake, a single copy of the text that slides out, leaves a gap and jumps back; below it the
first row with its two copies, which loops with no seam */
.stage[data-hb-mode="compare"]{display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:repeat(2,minmax(0,1fr))}
.stage[data-hb-mode="compare"] .solo{display:flex;flex-direction:column;justify-content:center;grid-row:1;border-bottom:2px solid rgba(255,255,255,.14)}
.stage[data-hb-mode="compare"] .rows{grid-row:2;justify-content:center}
.stage[data-hb-mode="compare"] .r1{border-bottom-color:transparent}
.stage[data-hb-mode="compare"] .side{display:block}
.side{left:12px}
.side.first{top:10px}
.side.second{top:calc(50% + 6px)}
.solo-track{display:flex;width:max-content;white-space:nowrap;animation:soloL linear infinite}
@keyframes soloL{from{transform:translateX(0)}to{transform:translateX(-100%)}}
</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="../text-clip-path-reveal/" rel="prev" aria-label="Previous: Text Clip-Path Reveal"><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>Text Clip-Path Reveal</span></a><a href="../text-morphing/" rel="next" aria-label="Next: Text Morphing"><span><span class="hb-dir">Next: </span>Text Morphing</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">05.06 · Text & Typography</p>
<h1>Marquee / Ticker</h1>
<p class="hb-lede">Text scrolls sideways in an endless loop, with no seam. Best for news tickers.</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, or point at a row (tap it on a phone) to stop just that row.</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">
<div class="rows" id="rows"></div>
<div class="zoom" id="zoom" aria-hidden="true" inert></div>
<div class="solo" id="solo" aria-hidden="true" inert></div>
<p class="lbl side first" aria-hidden="true" data-hb-caption>One copy</p>
<p class="lbl side second" aria-hidden="true" data-hb-caption>Two copies</p>
</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 strip is two identical copies end to end and the box is a window sliding over them; it jumps back at the second copy, which looks the same, so the jump never shows.</p>
<p data-hb-for="compare" hidden>On top, One copy: the text slides out, leaves a gap and jumps back. Below, Two copies: a second copy fills the gap, so the loop has no seam.</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="speed-lbl">Speed</p>
<div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
<button type="button" data-spd="50" aria-pressed="false">Slow</button>
<button type="button" data-spd="80" class="on" aria-pressed="true">Normal</button>
<button type="button" data-spd="130" aria-pressed="false">Fast</button>
</div>
<p class="hb-hint">How fast the text travels.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="size-lbl">Text size</p>
<div class="seg" id="size-seg" role="group" aria-labelledby="size-lbl">
<button type="button" data-size="32" aria-pressed="false">Small</button>
<button type="button" data-size="48" class="on" aria-pressed="true">Medium</button>
<button type="button" data-size="64" aria-pressed="false">Large</button>
</div>
<p class="hb-hint">Large type is the usual choice for brand strips.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="gap-lbl">Space between items</p>
<div class="seg" id="gap-seg" role="group" aria-labelledby="gap-lbl">
<button type="button" data-gap="24" aria-pressed="false">Tight</button>
<button type="button" data-gap="48" class="on" aria-pressed="true">Medium</button>
<button type="button" data-gap="80" aria-pressed="false">Wide</button>
</div>
<p class="hb-hint">The space around the text and the separator.</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="sep-lbl">Separator</p>
<div class="seg" id="sep-seg" role="group" aria-labelledby="sep-lbl">
<button type="button" data-sep="·" aria-pressed="false">Dot ·</button>
<button type="button" data-sep="★" aria-pressed="false">Star ★</button>
<button type="button" data-sep="—" aria-pressed="false">Dash —</button>
<button type="button" data-sep="✦" class="on" aria-pressed="true">Sparkle ✦</button>
</div>
<p class="hb-hint">The mark between repeats of the text.</p>
</div>
<div class="hb-setting">
<label class="hb-setting-name" for="text-inp">Your text</label>
<input class="hb-text" type="text" id="text-inp" value="Animation Handbook" autocomplete="off">
<p class="hb-hint">Type your own words to see them scroll.</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 marquee to [the text or items you want to scroll]. The text should scroll sideways in an endless loop with no visible jump: place two identical copies side by side, each at least as wide as the space it scrolls through, and move them by exactly one copy's width before starting over. Put a small mark between the repeats. Rows can run in opposite directions for a decorative band. Pointing at a row should stop it so people can read it, and a tap should do the same on touch screens. Screen readers should not announce the moving text again and again. If the visitor has reduced motion turned on, keep the text 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>News tickers</li><li>Brand strips</li><li>Client lists</li></ul>
<h3>Avoid on</h3>
<ul class="hb-tags hb-avoid"><li>Important messages</li><li>Long sentences</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 rows=document.getElementById('rows'),zoom=document.getElementById('zoom'),solo=document.getElementById('solo');
const reduceMQ=matchMedia('(prefers-reduced-motion: reduce)');
// Under reduced motion the loop starts paused, so both views are still pictures, and their notes say so, but only while the
// still picture is the posed one: once Play has moved it on, the notes say the markup's own words again, until a mode press or
// a rebuild poses the one copy anew. The shared script sends hb:pause on every press of Pause or Play, and once at boot under
// reduced motion, when it pauses the loop. A note is rewritten only when its words change, as its box reads changes out loud.
const notes=[...document.querySelectorAll('[data-hb-for]')],moving=notes.map(n=>n.textContent),still=[
'Inside, shown still: the strip is two identical copies end to end, and the arrow shows how far the box slides before it jumps back to the start.',
'Shown still: on top, One copy, the text has slid most of the way out and left a gap; below, Two copies, the second copy fills it.'];
let paused=reduceMQ.matches,posed=true;
function describe(){
const shown=reduceMQ.matches&&paused&&posed;
notes.forEach((n,i)=>{const words=shown?still[i]:moving[i];if(n.textContent!==words)n.textContent=words});
}
describe();
document.addEventListener('hb:pause',e=>{paused=e.detail.paused;if(!paused)posed=false;describe()});
const vars=document.documentElement.style;
const txtIn=document.getElementById('text-inp');
const noHover=matchMedia('(hover:none)');
let spd=80,separator='✦';
function makeItem(text,sep,reverse){
const item=document.createElement('div');item.className='marq-item'+(reverse?' rev-row':'');
item.textContent=text;
const s=document.createElement('span');s.className='sep';s.setAttribute('aria-hidden','true');s.textContent=sep;
item.appendChild(s);
return item;
}
function buildRow(text,sep,reverse,className){
const row=document.createElement('div');row.className='marq-row'+(className?' '+className:'');
const track=document.createElement('div');track.className='marq-track'+(reverse?' rev':'');track.setAttribute('aria-live','off');
row.appendChild(track);
rows.appendChild(row);
// One copy must be wider than the row, so repeat the item until it is, then duplicate that copy once
const probe=makeItem(text,sep,reverse);track.appendChild(probe);
const reps=Math.max(2,Math.ceil(row.clientWidth/Math.max(probe.offsetWidth,1))+1);
for(let i=1;i<reps*2;i++)track.appendChild(makeItem(text,sep,reverse));
updateSpeed(track);
// Tap toggles pause where there is no hover
row.addEventListener('click',()=>{if(noHover.matches)row.classList.toggle('paused')});
return row;
}
function getContent(){return txtIn.value.trim()?txtIn.value:'Animation Handbook'}
// Fraction of the loop a track has completed (0-1), so a duration change or rebuild can resume in place
function progressOf(track){
const an=track&&track.getAnimations()[0];const d=track&&track.durMs;
return an&&d&&an.currentTime!=null?(an.currentTime%d)/d:0;
}
function updateSpeed(track,frac){
const oneCopy=track.scrollWidth/2; // -50% travel distance
if(frac==null)frac=progressOf(track);
track.durMs=Math.round(oneCopy/spd*1000);
track.style.animationDuration=track.durMs+'ms';
// Changing duration keeps elapsed time, not progress: re-seat the animation so the text does not jump
const an=track.getAnimations()[0];if(an)an.currentTime=frac*track.durMs;
}
function rebuild(){
const text=getContent();
const frac=progressOf(stage.querySelector('.marq-track'));
rows.innerHTML='';
buildRow(text,separator,false,'r1');
buildRow(text,separator,true,'accent r2');
buildRow(text+' '+separator+' '+text,separator,false,'r3');
document.querySelectorAll('.marq-track').forEach(t=>updateSpeed(t,frac));
buildViews();
}
function refreshSpeeds(){
document.querySelectorAll('.marq-track').forEach(t=>updateSpeed(t));
}
// See inside and Compare are drawn from the first row as it stands (its text, its copies, its width and its speed) and built
// again with the rows, so every setting and Your text reach them. Sizes come from the first row, which is always shown.
function buildViews(){
const row=rows.querySelector('.r1'),track=row&&row.querySelector('.marq-track');
if(!track)return;
const copyW=track.scrollWidth/2,rowW=stage.clientWidth,rowH=row.offsetHeight;
// the zoom's side margins are 2% of the box's width, 10 to 20 pixels, as in the styles
const zoomW=Math.max(1,rowW-2*Math.min(20,Math.max(10,rowW*.02)));
const k=Math.min(1,zoomW/track.scrollWidth),h=rowH*k,cw=copyW*k;
zoom.innerHTML='';
const box=document.createElement('div');box.className='zin';box.style.height=h+115+'px';zoom.appendChild(box);
const add=(cls,css,words,to=box)=>{
const el=document.createElement(words===undefined?'div':'span');el.className=cls;
for(const [p,v] of Object.entries(css))el.style.setProperty(p,v);
if(words!==undefined){el.textContent=words;el.setAttribute('data-hb-caption','')}
to.appendChild(el);return el;
};
// the whole strip, drawn small enough to fit, with its two copies outlined and named
const strip=track.cloneNode(true);
strip.className='ztrack';strip.removeAttribute('aria-live');
strip.style.top=34+h/2-track.offsetHeight*k/2+'px';strip.style.transform=`scale(${k})`;
box.appendChild(strip);
add('zcopy',{left:'0px',top:'30px',width:cw+'px',height:h+8+'px'});
add('zcopy',{left:cw+'px',top:'30px',width:cw+'px',height:h+8+'px'});
add('lbl zcap',{left:'0px',top:'0px'},'Copy 1');
add('lbl zcap',{left:cw+4+'px',top:'0px'},'Copy 2, the same');
// where the second copy starts the window jumps back; the arrow under it is as long as the slide
add('zjump',{left:cw-1+'px',top:'22px',height:h+59+'px'});
// the box as a window over the strip, named under it: it slides one copy's width, as long as the row takes, then starts over
const win=add('zwin',{top:'26px',width:rowW*k+'px',height:h+16+'px','--zgo':cw+'px','animation-duration':track.durMs+'ms'});
add('lbl zcap',{},'In the box',win);
add('zarrow',{top:h+74+'px',width:cw+'px'});
add('lbl zcap zback',{left:cw+'px',top:h+93+'px'},'Jumps back here');
// Compare's mistake: the same strip as Copy 1 (the first row's own first copy), but only that one copy, sliding by its own
// width in the time the row takes, then starting over. The two halves differ only by the second copy.
solo.innerHTML='';
const srow=document.createElement('div');srow.className='marq-row solo-row';
const st=document.createElement('div');st.className='solo-track';
for(let i=0;i<track.children.length/2;i++)st.appendChild(track.children[i].cloneNode(true));
srow.appendChild(st);solo.appendChild(srow);
st.style.animationDuration=track.durMs+'ms';
syncWindow();
poseSolo();
}
// The window keeps time with the first row: both cover one copy's width in the same time. A window just shown starts a frame
// later than asked, so it is set again once it runs (a window hidden before that is let go quietly).
function syncWindow(){
const t=rows.querySelector('.r1 .marq-track'),w=zoom.querySelector('.zwin');
const a=t&&t.getAnimations()[0],b=w&&w.getAnimations()[0];
const sync=()=>{if(a.currentTime!=null&&b.playState!=='idle')b.currentTime=a.currentTime%t.durMs};
if(a&&b){sync();b.ready.then(sync,()=>{})}
}
// Compare's mistake starts at its telling moment: the one copy has slid so far that what is left of it covers 40% of the box,
// its last words beside a plain gap, and the jump back comes within seconds; under reduced motion the loop is paused, and it
// holds there. The copy's width is measured on the first row, which is always shown.
function poseSolo(){
const t=solo.querySelector('.solo-track'),a=t&&t.getAnimations()[0],r=rows.querySelector('.r1 .marq-track');
if(!(a&&a.effect&&r))return;
a.currentTime=Math.max(0,1-.4*stage.clientWidth/(r.scrollWidth/2))*a.effect.getComputedTiming().duration;
posed=true;describe();
}
// The mode switch: draws the mode at once. A view's animation starts when the view is shown, so the window is set to the first
// row's place then, and the mistake is posed. Pause and Slow motion reach every animation in the stage.
document.addEventListener('hb:mode',e=>{
syncWindow();
if(e.detail.mode==='compare')poseSolo();
});
reduceMQ.addEventListener('change',()=>{describe();if(reduceMQ.matches)poseSolo()});
txtIn.addEventListener('input',rebuild);
let resizeTimer,lastW=innerWidth;
addEventListener('resize',()=>{
if(innerWidth===lastW)return; // ignore mobile address-bar height changes
lastW=innerWidth;clearTimeout(resizeTimer);resizeTimer=setTimeout(rebuild,150);
});
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('speed-seg',d=>{spd=+d.spd;refreshSpeeds();buildViews()});
choices('size-seg',d=>{vars.setProperty('--marq-size',d.size+'px');rebuild()});
choices('gap-seg',d=>{vars.setProperty('--marq-gap',d.gap+'px');rebuild()});
choices('sep-seg',d=>{separator=d.sep;rebuild()});
rebuild();
if(document.fonts)document.fonts.ready.then(rebuild); // the site font can still be loading when the rows are first measured
</script>
</body>
</html>