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: move Rotate Word Carousel to the guided-steps page

matin0d60ae5b0795
diff --git a/animations/05-text-typography/rotate-word-carousel/README.md b/animations/05-text-typography/rotate-word-carousel/README.md
index 4e2fd77f..a32066b3 100644
--- a/animations/05-text-typography/rotate-word-carousel/README.md
+++ b/animations/05-text-typography/rotate-word-carousel/README.md
@@ -1,7 +1,7 @@
# Rotate Word Carousel
## What it is
-A rotate word carousel keeps a sentence almost entirely static while cycling one keyword through a list of alternatives. The pattern reads as: "We build [Websites / Apps / Brands / Systems]." Only the bracketed word animates — sliding out as the current word and sliding in as the next. This is the dominant hero headline pattern on agency, freelance, and SaaS landing pages.
+A rotating word keeps a sentence still while one word in it keeps changing: "We craft for Designers" becomes "We craft for Developers", then "We craft for Humans". The current word slides out of sight and the next one slides in from the other side, so each change is easy to notice while the rest of the line stays readable. It is a common headline on the home pages of studios and software products.
## When to use it
- Hero headlines that address multiple audiences: "Built for [Designers / Developers / Teams]"
@@ -73,10 +73,12 @@ setInterval(() => {
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Hold duration | 2000ms | How long each word stays visible — 1.5–3s is the readable range |
-| Transition duration | 400ms | 200ms = snappy; 600ms = deliberate |
-| Direction | Up/down | Up = word scrolls up like a slot machine; Left/right = word slides horizontally |
-| Color per word | Per-word accent | Unique color per word draws more attention to the change; uniform is calmer |
+| Slide direction | Up | Up and down move the word like a slot machine; left and right slide it sideways |
+| Speed | Normal | How long each slide takes: slow is 650ms, normal 400ms and fast 250ms |
+| Time on each word | Medium | How long each word stays: short is 1200ms, medium 2000ms and long 3200ms; 1.5 to 3 seconds is the readable range |
+| Different color per word | on | A new color for each word draws attention to the change; one color is calmer |
+| Your sentence | We craft for | The part of the headline that stays still |
+| Your words, one per line | Designers, Developers, Humans, Teams, Startups | The words that take turns |
## Production notes
- **Only one word should rotate**: multiple cycling sections in a single headline create chaos. The static context is what makes the rotating word legible — "We build for [X]" works because "We build for" never changes.
@@ -87,6 +89,6 @@ setInterval(() => {
- **Typed.js, Motion One**: both have built-in word cycling APIs. Typed.js (`strings: [...]` with `backSpeed`) is the most widely used.
## See also
-- [Text Morphing](../text-morphing/) — character-level transitions between words rather than whole-word slides
-- [Enter/Exit Typography](../enter-exit-typography/) — full-phrase cycling with enter and exit on the entire headline
-- [Typewriter Effect](../typewriter-effect/) — an alternative word-reveal pattern that types characters one by one
+- [Text Morphing](../text-morphing/) — one word changes into the next, letter by letter
+- [Enter/Exit Typography](../enter-exit-typography/) — whole phrases come in, hold and leave
+- [Typewriter Effect](../typewriter-effect/) — text typed one character at a time
diff --git a/animations/05-text-typography/rotate-word-carousel/index.html b/animations/05-text-typography/rotate-word-carousel/index.html
index c44473eb..65d249e3 100644
--- a/animations/05-text-typography/rotate-word-carousel/index.html
+++ b/animations/05-text-typography/rotate-word-carousel/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rotate Word Carousel — Animation Handbook</title>
- <meta name="description" content="One word cycles through a list while the sentence stays static — the classic hero pattern.">
+ <meta name="description" content="One word in a sentence keeps swapping for the next. Best for hero headlines.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/rotate-word-carousel/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,35 +12,25 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Rotate Word Carousel — Animation Handbook">
- <meta property="og:description" content="One word cycles through a list while the sentence stays static — the classic hero pattern.">
+ <meta property="og:description" content="One word in a sentence keeps swapping for the next. Best for hero headlines.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/rotate-word-carousel/">
<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="Rotate Word Carousel — Animation Handbook">
- <meta name="twitter:description" content="One word cycles through a list while the sentence stays static — the classic hero pattern.">
+ <meta name="twitter:description" content="One word in a sentence keeps swapping for the next. Best for hero 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": "Rotate Word Carousel", "name": "Rotate Word Carousel", "description": "One word cycles through a list while the sentence stays static — the classic hero pattern.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/rotate-word-carousel/", "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, Rotate Word Carousel"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Rotate Word Carousel", "name": "Rotate Word Carousel", "description": "One word in a sentence keeps swapping for the next. Best for hero headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/rotate-word-carousel/", "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, Rotate Word Carousel"}</script>
<style>
- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}
- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}
- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}
- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff6f8b;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--rot-dur:400ms;--hold-dur:2000ms;--rot-ease:cubic-bezier(.4,0,.2,1);--word-color:#ff6f8b}
+ :root{--ui-accent:#ff6f8b;--rot-dur:400ms;--rot-ease:cubic-bezier(.4,0,.2,1);--word-color:#ff6f8b}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}
- header{margin-bottom:20px}
- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#04060c;display:flex;align-items:center;justify-content:center;padding:32px;overflow:hidden}
- .headline{font-family:Georgia,'Times New Roman',serif;font-size:clamp(22px,3.5vw,42px);line-height:1.3;color:#fff;text-align:center;display:flex;flex-direction:column;align-items:center;gap:0}
+ .stage{display:flex;align-items:center;justify-content:center;background:#04060c;padding:32px;overflow:hidden}
+ .headline{font-weight:700;font-size:clamp(22px,3.5vw,42px);line-height:1.3;color:#fff;text-align:center;display:flex;flex-direction:column;align-items:center;gap:0}
.static-line{display:flex;align-items:center;flex-wrap:wrap;justify-content:center;gap:0.2em}
.static-text{white-space:nowrap;color:rgba(255,255,255,.75)}
.rot-container{position:relative;display:inline-block;overflow:hidden;vertical-align:middle}
.rot-word{
display:block;
color:var(--word-color);
- font-style:italic;
white-space:nowrap;
will-change:transform,opacity;
transition:transform var(--rot-dur) var(--rot-ease),opacity var(--rot-dur) ease
@@ -55,53 +45,29 @@
.rot-word.enter-right{transform:translateX(110%);opacity:0}
/* Multi-color classes */
.wc0{color:#58a6ff}.wc1{color:#56d364}.wc2{color:#d2a8ff}.wc3{color:#ffa657}.wc4{color:#f85149}
- /* Word indicators */
- .word-dots{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;margin-top:16px}
- .word-dot{font-size:9px;padding:3px 8px;border-radius:3px;background:var(--ui-border);color:var(--ui-muted);letter-spacing:0.5px;transition:background .2s,color .2s}
- .word-dot.active{background:var(--ui-accent);color:#000}
- /* Panel */
- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
- .div{height:1px;background:var(--ui-border)}
- .sr{display:flex;align-items:center;gap:6px;font-size:10px}
- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
- .sv{width:44px;text-align:right;color:var(--ui-text)}
- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
- input[type=text]:focus{border-color:var(--ui-accent)}
- textarea{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:88px;line-height:1.5;outline:none}
- textarea:focus{border-color:var(--ui-accent)}
- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:380px}}
@media(prefers-reduced-motion:reduce){.rot-word{transition:none!important;transform:none!important;opacity:1!important}}
</style>
-<style id="ah-inject">
-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
-body{padding-top:46px}
-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}
-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}
-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}
-.ah-home{color:var(--ah-ink);font-weight:600}
-.ah-actions{display:flex;align-items:center;gap:2px}
-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}
-.ah-copied{color:var(--ah-accent)!important}
-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}
-@media print{.ah-bar{display:none}body{padding-top:0}}
-</style>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
-<body>
-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../enter-exit-typography/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../glitch-text/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/05-text-typography/rotate-word-carousel/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Rotate Word Carousel</h1>
- <p>One word cycles through a list while the sentence stays static — the classic hero pattern.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <div style="display:flex;flex-direction:column;align-items:center">
+<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="../enter-exit-typography/" rel="prev" aria-label="Previous: Enter/Exit Typography"><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>Enter/Exit Typography</span></a><a href="../glitch-text/" rel="next" aria-label="Next: Glitch Text"><span><span class="hb-dir">Next: </span>Glitch Text</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">05.11 · Text &amp; Typography</p>
+ <h1>Rotate Word Carousel</h1>
+ <p class="hb-lede">One word in a sentence keeps swapping for the next. Best for hero 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 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="stage hb-dots hb-grow">
<div class="headline" id="headline">
<div class="static-line">
<span class="static-text" id="static-text">We craft for</span>
@@ -110,70 +76,143 @@ body{padding-top:46px}
</div>
</div>
</div>
- <div class="word-dots" id="word-dots"></div>
</div>
- </div>
- <aside>
- <p class="note">Only ONE word rotates — the sentence is static. Keep words similar in length to minimize layout shift. aria-live announces each new word to screen readers.</p>
- <div class="lbl">Hold Duration</div>
- <div class="sr"><input type="range" id="hold-sl" min="1000" max="5000" value="2000" step="100"><span class="sv" id="hold-v">2.0s</span></div>
- <div class="lbl">Transition Duration</div>
- <div class="sr"><input type="range" id="dur-sl" min="200" max="800" value="400" step="50"><span class="sv" id="dur-v">400ms</span></div>
- <div class="lbl">Direction</div>
- <select id="dir-sel">
- <option value="up" selected>Up</option>
- <option value="down">Down</option>
- <option value="left">Left</option>
- <option value="right">Right</option>
- </select>
- <label class="tog"><input type="checkbox" id="color-tog" checked><span>Different color per word</span></label>
- <div class="div"></div>
- <div class="lbl">Static text</div>
- <input type="text" id="static-inp" value="We craft for">
- <div class="lbl">Rotating words</div>
- <textarea id="words-inp">Designers
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause 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 autocomplete="off"><span>Slow motion</span></label>
+ </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="dir-lbl">Slide direction</p>
+ <div class="seg" id="dir-seg" role="group" aria-labelledby="dir-lbl">
+ <button type="button" data-dir="up" class="on" aria-pressed="true">Up</button>
+ <button type="button" data-dir="down" aria-pressed="false">Down</button>
+ <button type="button" data-dir="left" aria-pressed="false">Left</button>
+ <button type="button" data-dir="right" aria-pressed="false">Right</button>
+ </div>
+ <p class="hb-hint">Which way the words slide.</p>
+ </div>
+ <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-dur="650" aria-pressed="false">Slow</button>
+ <button type="button" data-dur="400" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-dur="250" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How fast one word slides out and the next in.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="hold-lbl">Time on each word</p>
+ <div class="seg" id="hold-seg" role="group" aria-labelledby="hold-lbl">
+ <button type="button" data-hold="1200" aria-pressed="false">Short</button>
+ <button type="button" data-hold="2000" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-hold="3200" aria-pressed="false">Long</button>
+ </div>
+ <p class="hb-hint">How long each word stays still to be read.</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">
+ <label class="hb-switch-row"><span>Different color per word</span><input class="hb-switch" type="checkbox" role="switch" id="color-tog" checked autocomplete="off"></label>
+ <p class="hb-hint">A new color draws the eye to each change.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-setting-name" for="sentence-inp">Your sentence</label>
+ <input class="hb-text" type="text" id="sentence-inp" value="We craft for" autocomplete="off">
+ <p class="hb-hint">The words that stay still before the changing one.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-setting-name" for="words-inp">Your words, one per line</label>
+ <textarea class="hb-text" id="words-inp" autocomplete="off">Designers
Developers
Humans
Teams
Startups</textarea>
- <button class="rst" id="restart-btn">↺ Restart</button>
- </aside>
-</div>
+ <p class="hb-hint">Words of similar length keep the sentence steady.</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 rotating word to [your headline, with the word that should change]. Keep the rest of the sentence still and swap only that one word: the current word slides out of sight and the next one slides in from the opposite side, clipped by an invisible box so it seems to come from behind the text. Hold each word long enough to read, then move on, repeating the list forever. Words of similar length keep the sentence from jumping. Screen readers should hear each new word once. If the visitor has reduced motion turned on, swap the words without sliding. 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>
+ </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>Hero headlines</li><li>Taglines</li><li>Service lists</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Body text</li><li>Long word lists</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="#top">Back to top ↑</a></footer>
<script>
- let wordIdx=0,timer=null,run=0;
const rotWord=document.getElementById('rot-word');
- const rotContainer=document.getElementById('rot-container');
const staticText=document.getElementById('static-text');
- const dotsEl=document.getElementById('word-dots');
-
- function getWords(){return document.getElementById('words-inp').value.split('\n').map(w=>w.trim()).filter(Boolean)}
- function getDur(){return+document.getElementById('dur-sl').value}
- function getHold(){return+document.getElementById('hold-sl').value}
- function getDir(){return document.getElementById('dir-sel').value}
+ const vars=document.documentElement.style;
+ const slowTog=document.getElementById('slow-tog');
+ const colorTog=document.getElementById('color-tog');
+ const sentenceIn=document.getElementById('sentence-inp');
+ const wordsIn=document.getElementById('words-inp');
const COLORS=['wc0','wc1','wc2','wc3','wc4'];
const outClasses=['out-up','out-down','out-left','out-right'];
const enterClasses=['enter-below','enter-above','enter-left','enter-right'];
+ const outMap={up:'out-up',down:'out-down',left:'out-left',right:'out-right'};
+ const enterMap={up:'enter-below',down:'enter-above',left:'enter-right',right:'enter-left'};
+ let dir='up',rotDur=400,hold=2000,wordIdx=0,timer=null,run=0,sliding=false,paused=false;
- function buildDots(words){
- dotsEl.innerHTML='';
- words.forEach((w,i)=>{const d=document.createElement('div');d.className='word-dot'+(i===wordIdx?' active':'');d.textContent=w;dotsEl.appendChild(d);});
- }
- function updateDots(i){dotsEl.querySelectorAll('.word-dot').forEach((d,j)=>d.classList.toggle('active',j===i));}
+ function getWords(){return wordsIn.value.split('\n').map(w=>w.trim()).filter(Boolean)}
+ function dur(){return slowTog.checked?rotDur*3:rotDur}
function setColor(el,i){
el.classList.remove(...COLORS);
- if(document.getElementById('color-tog').checked){el.style.color='';el.classList.add(COLORS[i%COLORS.length]);}
+ if(colorTog.checked){el.style.color='';el.classList.add(COLORS[i%COLORS.length])}
else el.style.color='var(--word-color)';
}
+ // One slide: the current word leaves, the next word is swapped in off-screen (transition off) and then
+ // slides to rest. Slow motion stretches --rot-dur and the two timers below that wait for it; the 20ms
+ // step between the swap and the entry transition stays the same either way.
function transitionTo(nextWord,nextIdx,done){
- const dir=getDir(),id=run;
- const outMap={up:'out-up',down:'out-down',left:'out-left',right:'out-right'};
- const enterMap={up:'enter-below',down:'enter-above',left:'enter-right',right:'enter-left'};
+ const d=dur(),id=run;
+ vars.setProperty('--rot-dur',d+'ms');
rotWord.classList.add(outMap[dir]);
setTimeout(()=>{
if(id!==run)return; // a restart superseded this transition
- // swap word
rotWord.textContent=nextWord;
setColor(rotWord,nextIdx);
// jump to the entry side without transitioning from the exit side
@@ -182,26 +221,28 @@ Startups</textarea>
rotWord.classList.add(enterMap[dir]);
void rotWord.offsetWidth;
rotWord.style.transition='';
- // timer (not rAF) so the loop keeps advancing when the tab is throttled
setTimeout(()=>{
if(id!==run)return;
rotWord.classList.remove(...enterClasses);
- setTimeout(()=>{if(id===run)done()},getDur()+50);
+ setTimeout(()=>{if(id===run)done()},d+50);
},20);
- },getDur()+30);
+ },d+30);
}
+ // A slide, then done() marks it finished and, while not paused, schedules the next one after `hold`.
function cycle(){
const words=getWords();if(words.length<2)return;
const next=(wordIdx+1)%words.length;
+ sliding=true;
transitionTo(words[next],next,()=>{
- wordIdx=next;updateDots(wordIdx);
- timer=setTimeout(cycle,getHold());
+ wordIdx=next;
+ sliding=false;
+ if(!paused)timer=setTimeout(cycle,hold);
});
}
function start(){
- if(timer)clearTimeout(timer);wordIdx=0;run++;
+ clearTimeout(timer);wordIdx=0;run++;sliding=false;
const words=getWords();if(!words.length)return;
// snap back to rest without replaying the exit slide in reverse
rotWord.style.transition='none';
@@ -210,22 +251,42 @@ Startups</textarea>
rotWord.style.transition='';
rotWord.textContent=words[0];
setColor(rotWord,0);
- staticText.textContent=document.getElementById('static-inp').value;
- buildDots(words);
- timer=setTimeout(cycle,getHold());
+ if(!paused)timer=setTimeout(cycle,hold);
}
- document.getElementById('restart-btn').addEventListener('click',start);
- document.getElementById('static-inp').addEventListener('input',e=>{staticText.textContent=e.target.value});
- document.getElementById('words-inp').addEventListener('change',start);
- document.getElementById('hold-sl').addEventListener('input',e=>{document.getElementById('hold-v').textContent=(e.target.value/1000).toFixed(1)+'s'});
- document.getElementById('dur-sl').addEventListener('input',e=>{document.getElementById('dur-v').textContent=e.target.value+'ms';document.documentElement.style.setProperty('--rot-dur',e.target.value+'ms')});
- document.getElementById('dir-sel').addEventListener('change',()=>{});
- document.getElementById('color-tog').addEventListener('change',()=>setColor(rotWord,wordIdx));
+ // Registered at the top level, before the shared script (deferred) can run: under reduced motion it pauses
+ // the loop on arrival, which this listener must catch. Paused clears only the hold timer — a slide already
+ // under way finishes and its own done() schedules nothing. Unpausing mid-slide does nothing here; the
+ // slide's done() will schedule the next hold once it sees the loop is no longer paused. Only one chain of
+ // timers ever runs, so the next Pause always stops the loop.
+ document.addEventListener('hb:pause',e=>{
+ paused=e.detail.paused;
+ if(paused){
+ clearTimeout(timer);
+ }else if(!sliding){
+ clearTimeout(timer);
+ timer=setTimeout(cycle,hold);
+ }
+ });
+
+ sentenceIn.addEventListener('input',e=>{staticText.textContent=e.target.value});
+ wordsIn.addEventListener('input',start);
+
+ 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('dir-seg',d=>{dir=d.dir});
+ choices('speed-seg',d=>{rotDur=+d.dur;vars.setProperty('--rot-dur',dur()+'ms')});
+ choices('hold-seg',d=>{hold=+d.hold});
+ colorTog.addEventListener('change',()=>setColor(rotWord,wordIdx));
rotWord.setAttribute('aria-live','polite');
+ vars.setProperty('--rot-dur',rotDur+'ms');
start();
</script>
-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
</html>
diff --git a/index.html b/index.html
index e0075502..b9de16e3 100644
--- a/index.html
+++ b/index.html
@@ -997,7 +997,7 @@ const CATS=[
['text-gradient-animation','Text Gradient Animation','background-clip: text with animated background-position flows color through the characters.'],
['outline-to-fill','Outline to Fill','Hollow letters fill with color, as a wipe or a fade. Best for big headlines.'],
['enter-exit-typography','Enter/Exit Typography','Each phrase comes in, stays long enough to read, then leaves. Best for slogans.'],
- ['rotate-word-carousel','Rotate Word Carousel','One keyword cycles through a list while the surrounding sentence stays static.'],
+ ['rotate-word-carousel','Rotate Word Carousel','One word in a sentence keeps swapping for the next. Best for hero headlines.'],
['glitch-text','Glitch Text','Text tears into red and cyan strips like a broken signal. Best for bold titles.'],
['text-on-path','Text on a Path','Text flows along an SVG curve via textPath with an animated startOffset — wave, arc, or circle.'],
['wavy-text','Wavy Text','Per-letter sine-wave bob with a staggered delay sends a wave travelling across the word.'],