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: a Learn page with a 25-step learning path in five chapters, and tests that keep every page of the path in step with it

matin38d31118d4dc
diff --git a/learn/index.html b/learn/index.html
new file mode 100644
index 00000000..43de43f9
--- /dev/null
+++ b/learn/index.html
@@ -0,0 +1,112 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Learn Web Animation — Animation Handbook</title>
+ <meta name="description" content="25 short lessons, from easy to advanced. You watch and try; you never write code.">
+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/learn/">
+ <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="website">
+ <meta property="og:site_name" content="Animation Handbook">
+ <meta property="og:title" content="Learn Web Animation — Animation Handbook">
+ <meta property="og:description" content="25 short lessons, from easy to advanced. You watch and try; you never write code.">
+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/learn/">
+ <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="Learn Web Animation — Animation Handbook">
+ <meta name="twitter:description" content="25 short lessons, from easy to advanced. You watch and try; you never write code.">
+ <meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
+ <style>
+ :root{--ui-accent:#c8f169}
+ .hb-chapter{display:flex;flex-direction:column;gap:14px;padding-top:clamp(28px,4vw,36px);border-top:1px solid var(--hb-line)}
+ .hb-chapter h2{margin:0;font:700 clamp(22px,2.6vw,26px)/1.2 var(--hb-font);letter-spacing:-.015em;color:var(--hb-ink)}
+ .hb-chapter h2 span{display:block;margin-bottom:4px;font:600 14px/1.3 var(--hb-font);letter-spacing:.04em;color:var(--hb-accent)}
+ .hb-path{display:flex;flex-direction:column;gap:10px;margin:0;padding:0;list-style:none}
+ .hb-path li > a,.hb-path li > div{display:grid;grid-template-columns:44px minmax(0,1fr);column-gap:16px;row-gap:2px;align-items:center;
+ padding:14px 18px;border:1px solid rgba(255,255,255,.12);border-radius:10px;text-decoration:none}
+ .hb-path .n{grid-row:1/span 3;display:flex;align-items:center;justify-content:center;width:44px;height:44px;border-radius:50%;
+ border:1px solid var(--hb-edge);font:700 16px/1 var(--hb-font);color:var(--hb-ink)}
+ .hb-path [data-kind="idea"] .n{border-color:var(--hb-accent);background:var(--hb-accent);color:#0b0b0d}
+ .hb-path .k{font:600 13px/1.3 var(--hb-font);color:var(--hb-muted)}
+ .hb-path b{font:700 18px/1.25 var(--hb-font);color:var(--hb-ink)}
+ .hb-path .line{font:400 15px/1.45 var(--hb-font);color:var(--hb-dim)}
+ .hb-path [data-soon] > div{border-style:dashed}
+ .hb-path [data-soon] b,.hb-path [data-soon] .line{color:var(--hb-muted)}
+ @media(hover:hover){.hb-path a:hover{border-color:color-mix(in srgb,var(--hb-accent) 55%,transparent)}}
+ </style>
+ <link rel="stylesheet" href="../assets/css/demo-page.css?v=8">
+ <script src="../assets/js/demo-page.js?v=8" defer></script>
+</head>
+<body class="hb hb-learn">
+<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>
+ <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">Learning path</p>
+ <h1>Learn web animation</h1>
+ <p class="hb-lede">25 short lessons, from easy to advanced. You watch and try; you never write code.</p>
+ </header>
+
+ <section class="hb-chapter" aria-labelledby="ch-1">
+ <h2 id="ch-1"><span>Chapter 1</span>Appear and leave</h2>
+ <ol class="hb-path">
+ <li data-step="1" data-kind="idea" data-soon><div><span class="n">1</span><span class="k">Idea · Not built yet</span><b>How long it takes</b><span class="line">Fast feels snappy and slow feels calm: pick the time that fits the moment.</span></div></li>
+ <li data-step="2" data-kind="animation"><a href="../animations/02-entrance-and-exit/fade-in-out/"><span class="n">2</span><span class="k">Animation</span><b>Fade In / Fade Out</b><span class="line">Fades in to appear and fades out to leave.</span></a></li>
+ <li data-step="3" data-kind="idea" data-soon><div><span class="n">3</span><span class="k">Idea · Not built yet</span><b>Slowing down</b><span class="line">Real things speed up and slow down, so smooth animations do too.</span></div></li>
+ <li data-step="4" data-kind="animation"><a href="../animations/02-entrance-and-exit/slide-in/"><span class="n">4</span><span class="k">Animation</span><b>Slide In</b><span class="line">Travels into place from one edge.</span></a></li>
+ <li data-step="5" data-kind="animation"><a href="../animations/02-entrance-and-exit/scale-in/"><span class="n">5</span><span class="k">Animation</span><b>Scale In / Zoom In</b><span class="line">Grows from smaller to full size.</span></a></li>
+ </ol>
+ </section>
+
+ <section class="hb-chapter" aria-labelledby="ch-2">
+ <h2 id="ch-2"><span>Chapter 2</span>Answer the visitor</h2>
+ <ol class="hb-path">
+ <li data-step="6" data-kind="idea" data-soon><div><span class="n">6</span><span class="k">Idea · Not built yet</span><b>Answer every action</b><span class="line">A press, a tap or a hover gets a quick, small reply, so people know it worked.</span></div></li>
+ <li data-step="7" data-kind="animation"><a href="../animations/04-micro-interactions/button-press-scale/"><span class="n">7</span><span class="k">Animation</span><b>Button Press Scale</b><span class="line">Shrinks as you press it and springs back as you let go.</span></a></li>
+ <li data-step="8" data-kind="animation"><a href="../animations/04-micro-interactions/hover-state/"><span class="n">8</span><span class="k">Animation</span><b>Hover State Animation</b><span class="line">Six ways a card can react when you point at it.</span></a></li>
+ <li data-step="9" data-kind="animation"><a href="../animations/04-micro-interactions/toggle-switch/"><span class="n">9</span><span class="k">Animation</span><b>Toggle / Switch Slide</b><span class="line">The knob slides across as the switch turns on or off.</span></a></li>
+ <li data-step="10" data-kind="animation"><a href="../animations/04-micro-interactions/loading-spinner/"><span class="n">10</span><span class="k">Animation</span><b>Loading Spinner</b><span class="line">Six small shapes loop to show that something is loading.</span></a></li>
+ </ol>
+ </section>
+
+ <section class="hb-chapter" aria-labelledby="ch-3">
+ <h2 id="ch-3"><span>Chapter 3</span>Move with the scroll</h2>
+ <ol class="hb-path">
+ <li data-step="11" data-kind="idea" data-soon><div><span class="n">11</span><span class="k">Idea · Not built yet</span><b>Follows the scroll</b><span class="line">Some animations play by themselves; others move only when you scroll.</span></div></li>
+ <li data-step="12" data-kind="animation"><a href="../animations/01-scroll-based/reveal-on-scroll/"><span class="n">12</span><span class="k">Animation</span><b>Reveal on Scroll</b><span class="line">Cards appear as they cross a line in the box.</span></a></li>
+ <li data-step="13" data-kind="idea" data-soon><div><span class="n">13</span><span class="k">Idea · Not built yet</span><b>One after another</b><span class="line">A short wait between items leads the eye through a group.</span></div></li>
+ <li data-step="14" data-kind="animation"><a href="../animations/01-scroll-based/stagger-reveal/"><span class="n">14</span><span class="k">Animation</span><b>Stagger Reveal</b><span class="line">Items in a group appear one after another as it scrolls in.</span></a></li>
+ <li data-step="15" data-kind="animation"><a href="../animations/01-scroll-based/progress-bar/"><span class="n">15</span><span class="k">Animation</span><b>Progress Bar</b><span class="line">A bar fills as you read down the page.</span></a></li>
+ </ol>
+ </section>
+
+ <section class="hb-chapter" aria-labelledby="ch-4">
+ <h2 id="ch-4"><span>Chapter 4</span>Change pages</h2>
+ <ol class="hb-path">
+ <li data-step="16" data-kind="idea" data-soon><div><span class="n">16</span><span class="k">Idea · Not built yet</span><b>Keep your place</b><span class="line">When the page changes, motion shows where things went.</span></div></li>
+ <li data-step="17" data-kind="animation"><a href="../animations/03-page-transitions/crossfade/"><span class="n">17</span><span class="k">Animation</span><b>Crossfade Transition</b><span class="line">The old page fades out as the new one fades in.</span></a></li>
+ <li data-step="18" data-kind="animation"><a href="../animations/03-page-transitions/slide-transition/"><span class="n">18</span><span class="k">Animation</span><b>Slide Transition</b><span class="line">Pages slide across, and going back slides the other way.</span></a></li>
+ <li data-step="19" data-kind="animation"><a href="../animations/03-page-transitions/shared-element-transition/"><span class="n">19</span><span class="k">Animation</span><b>Shared Element Transition</b><span class="line">A picture grows from the list into the next page's header.</span></a></li>
+ <li data-step="20" data-kind="animation"><a href="../animations/03-page-transitions/flip-technique/"><span class="n">20</span><span class="k">Animation</span><b>FLIP Technique</b><span class="line">Cards glide to their new places when the layout changes.</span></a></li>
+ </ol>
+ </section>
+
+ <section class="hb-chapter" aria-labelledby="ch-5">
+ <h2 id="ch-5"><span>Chapter 5</span>Depth and 3D</h2>
+ <ol class="hb-path">
+ <li data-step="21" data-kind="idea" data-soon><div><span class="n">21</span><span class="k">Idea · Not built yet</span><b>Far things move slower</b><span class="line">Near things pass quickly and far things slowly: that is how depth looks.</span></div></li>
+ <li data-step="22" data-kind="animation"><a href="../animations/01-scroll-based/parallax-scrolling/"><span class="n">22</span><span class="k">Animation</span><b>Parallax Scrolling</b><span class="line">Far layers move slower than near ones as you scroll.</span></a></li>
+ <li data-step="23" data-kind="animation"><a href="../animations/06-3d-advanced/parallax-3d-tilt/"><span class="n">23</span><span class="k">Animation</span><b>Parallax 3D Tilt</b><span class="line">A card tilts toward your pointer, and a light slides over it.</span></a></li>
+ <li data-step="24" data-kind="animation"><a href="../animations/06-3d-advanced/flip-card-3d/"><span class="n">24</span><span class="k">Animation</span><b>3D Flip Card</b><span class="line">A card turns over in 3D to show its back.</span></a></li>
+ <li data-step="25" data-kind="idea" data-soon><div><span class="n">25</span><span class="k">Idea · Not built yet</span><b>Less is more</b><span class="line">When not to animate, and how to respect people who ask for less motion.</span></div></li>
+ </ol>
+ </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>
+</body>
+</html>
diff --git a/tests/learn.test.js b/tests/learn.test.js
new file mode 100644
index 00000000..06a621df
--- /dev/null
+++ b/tests/learn.test.js
@@ -0,0 +1,141 @@
+// Static checks for the Learn pages: the learning path on learn/index.html (the single source of truth for the path), the idea
+// lessons in learn/<slug>/, and the lesson line and lesson nav on every page of the path that has them.
+// Run from the repo root: node --test "tests/*.test.js"
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const path = require('node:path');
+
+const ROOT = path.resolve(__dirname, '..');
+const LEARN = path.join(ROOT, 'learn');
+const ANIM = path.join(ROOT, 'animations');
+const read = f => fs.readFileSync(f, 'utf8');
+const count = (s, sub) => s.split(sub).length - 1;
+const HUB = read(path.join(LEARN, 'index.html'));
+const HOME = read(path.join(ROOT, 'index.html'));
+
+// The steps of the path in page order: { n, kind, soon, href (null while not built), title, body }.
+const STEPS = [...HUB.matchAll(/<li data-step="(\d+)" data-kind="(idea|animation)"( data-soon)?>([\s\S]*?)<\/li>/g)].map(m => {
+ const link = m[4].match(/<a href="([^"]+)"/);
+ return { n: Number(m[1]), kind: m[2], soon: !!m[3], href: link ? link[1] : null, title: (m[4].match(/<b>([^<]+)<\/b>/) || [])[1], body: m[4] };
+});
+const dirOf = href => path.resolve(LEARN, href);
+const h1Of = dir => ((read(path.join(dir, 'index.html')).match(/<h1>([^<]+)<\/h1>/) || [])[1] || '').replace(/&amp;/g, '&');
+const LESSONS = fs.readdirSync(LEARN, { withFileTypes: true })
+ .filter(d => d.isDirectory() && fs.existsSync(path.join(LEARN, d.name, 'index.html'))).map(d => path.join(LEARN, d.name));
+const FOOTER = '<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>';
+const STAR = '<a class="hb-star" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener" aria-label="Star on GitHub">';
+const version = (html, file) => (html.match(new RegExp(`demo-page\\.${file}\\?v=(\\d+)`)) || [])[1];
+
+test('the path has 25 steps in five chapters of five, numbered in order', () => {
+ assert.deepEqual(STEPS.map(s => s.n), Array.from({ length: 25 }, (_, i) => i + 1));
+ const chapters = [...HUB.matchAll(/<section class="hb-chapter"[\s\S]*?<\/section>/g)].map(m => count(m[0], '<li data-step='));
+ assert.deepEqual(chapters, [5, 5, 5, 5, 5]);
+});
+
+test('every built step links to an existing page and shows its title; a step not built yet has no link and says so', () => {
+ for (const s of STEPS) {
+ if (s.soon) {
+ assert.equal(s.href, null, `step ${s.n} has no link`);
+ assert.ok(s.body.includes('Not built yet'), `step ${s.n} says Not built yet`);
+ continue;
+ }
+ assert.ok(s.href, `step ${s.n} has a link`);
+ const dir = dirOf(s.href);
+ assert.ok(fs.existsSync(path.join(dir, 'index.html')), `step ${s.n}: ${s.href} exists`);
+ assert.equal(s.title, h1Of(dir), `step ${s.n} shows the page's title`);
+ assert.ok(dir.startsWith((s.kind === 'idea' ? LEARN : ANIM) + path.sep), `step ${s.n}: ideas live in learn/, animations in animations/`);
+ }
+});
+
+test('every idea lesson in learn/ is a built step of the path', () => {
+ for (const dir of LESSONS) {
+ assert.ok(STEPS.some(s => s.href && s.kind === 'idea' && dirOf(s.href) === dir), `${path.basename(dir)} is a built idea step`);
+ }
+});
+
+// Every page of the path that has a lesson line or lesson nav: each idea lesson, and any animation page that carries them.
+const onPath = STEPS.filter(s => s.href).map(s => ({ step: s, dir: dirOf(s.href) }))
+ .filter(p => fs.existsSync(path.join(p.dir, 'index.html')) && read(path.join(p.dir, 'index.html')).includes('class="hb-lesson'));
+for (const { step, dir } of onPath) {
+ test(`step ${step.n} (${step.title}): its lesson line and lesson nav match the Learn page`, () => {
+ const html = read(path.join(dir, 'index.html'));
+ const learnHref = path.relative(dir, LEARN).split(path.sep).join('/') + '/';
+ const line = step.kind === 'idea' ? `<p class="hb-cat">Lesson ${step.n} of 25 · Idea</p>`
+ : `<p class="hb-lesson"><a href="${learnHref}">Learning path · Lesson ${step.n} of 25</a></p>`;
+ assert.ok(html.includes(line), `lesson line: ${line}`);
+ const nav = html.match(/<nav class="hb-lesson-nav" aria-label="Learning path">([\s\S]*?)<\/nav>/);
+ assert.ok(nav, 'lesson nav');
+ assert.ok(nav[1].includes('<p class="hb-lesson-title">Learning path</p>'), 'lesson nav title');
+ const prev = STEPS[step.n - 2], next = STEPS[step.n];
+ for (const [cls, other, label] of [['hb-lesson-prev', prev, prev && `← Lesson ${prev.n}`], ['hb-lesson-next', next, next && `Lesson ${next.n} →`]]) {
+ const a = nav[1].match(new RegExp(`<a class="${cls}" href="([^"]+)"><span>([^<]+)</span><b>([^<]+)</b></a>`));
+ if (!other) { assert.equal(a, null, `no ${cls} at the end of the path`); continue; }
+ assert.ok(other.href, `step ${other.n}, next to step ${step.n}, is built`);
+ assert.ok(a, cls);
+ assert.equal(a[2], label, `${cls} label`);
+ assert.equal(a[3], other.title, `${cls} title`);
+ assert.equal(path.resolve(dir, a[1]), dirOf(other.href), `${cls} opens step ${other.n}`);
+ }
+ assert.ok(nav[1].includes(`<a class="hb-lesson-all" href="${learnHref}">All 25 lessons</a>`), 'All 25 lessons');
+ if (step.kind === 'idea') {
+ for (const [rel, other, word] of [['prev', prev, 'Previous'], ['next', next, 'Next']]) {
+ const a = html.match(new RegExp(`<a href="([^"]+)" rel="${rel}" aria-label="${word} lesson: ([^"]+)">`));
+ assert.ok(a, `top bar ${rel} link`);
+ assert.equal(path.resolve(dir, a[1]), dirOf(other.href), `top bar ${rel} opens step ${other.n}`);
+ assert.equal(a[2], other.title, `top bar ${rel} names step ${other.n}`);
+ }
+ }
+ });
+}
+
+for (const file of [path.join(LEARN, 'index.html'), ...LESSONS.map(d => path.join(d, 'index.html'))]) {
+ const name = path.relative(ROOT, file).split(path.sep).join('/');
+ test(`${name}: the shared frame (top bar with the Star link, footer, shared files at the home page's version) and no code`, () => {
+ const html = read(file);
+ assert.match(html, /<body class="hb hb-learn"/, 'body class hb hb-learn');
+ assert.equal(count(html, '<nav class="hb-bar"'), 1);
+ assert.ok(html.includes(STAR), 'the Star link in the top bar');
+ assert.equal(count(html, '<main class="hb-page">'), 1);
+ assert.equal(count(html, '<header class="hb-head">'), 1);
+ assert.ok(html.replace(/>\s+</g, '><').includes(FOOTER), 'the shared footer');
+ // The home page links only demo-page.js (it has its own styles), so its version N is the script's.
+ for (const f of ['css', 'js']) assert.equal(version(html, f), version(HOME, 'js'), `demo-page.${f} at the home page's version`);
+ assert.ok(!/`|<code|<pre/.test(html.replace(/<script[\s\S]*?<\/script>/g, '').replace(/<style[\s\S]*?<\/style>/g, '')), 'no code on the page');
+ assert.ok(!html.includes('hb-view'), 'no old hb-view markup');
+ });
+}
+
+test('the Learn page names itself and has five chapters', () => {
+ assert.ok(HUB.includes('<h1>Learn web animation</h1>'));
+ assert.ok(HUB.includes('<p class="hb-lede">25 short lessons, from easy to advanced. You watch and try; you never write code.</p>'));
+ assert.equal(count(HUB, '<section class="hb-chapter"'), 5);
+});
+
+for (const dir of LESSONS) {
+ test(`learn/${path.basename(dir)}: an idea lesson with a stage, Why it works, Where you'll see it and no prompt`, () => {
+ const html = read(path.join(dir, 'index.html'));
+ const body = html.match(/<body class="hb hb-learn" data-hb-kind="(once|loop|scroll|do)"( data-hb-autoplay)?(?: data-hb-motion-note="[^"]*")?>/);
+ assert.ok(body, 'the body declares the page kind');
+ for (const part of ['<section class="hb-step hb-watch"', '<div class="hb-player">', '<section class="hb-why"', '<section class="hb-seen"', '<nav class="hb-lesson-nav"']) {
+ assert.equal(count(html, part), 1, `exactly one ${part}`);
+ }
+ assert.ok(!html.includes('hb-prompt'), 'no prompt');
+ if (body[1] === 'loop') assert.equal(count(html, 'data-hb-pause'), 1, 'a loop has Pause');
+ if (body[1] === 'scroll') {
+ assert.ok(body[2], 'a scroll lesson scrolls once on arrival');
+ assert.equal(count(html, 'data-hb-autoscroll'), 1, 'Play');
+ assert.equal(count(html, 'data-hb-top'), 1, 'Back to top');
+ }
+ const why = html.match(/<section class="hb-why"[\s\S]*?<\/section>/)[0].replace(/<[^>]+>/g, ' ');
+ const sentences = why.replace('Why it works', '').split(/[.!?](?:\s|$)/).filter(s => s.trim()).length;
+ assert.ok(sentences >= 2 && sentences <= 4, `Why it works has ${sentences} sentences`);
+ const seen = [...html.match(/<section class="hb-seen"[\s\S]*?<\/section>/)[0].matchAll(/<a class="hb-rel" href="([^"]+)"><b>([^<]+)<\/b>/g)];
+ assert.ok(seen.length >= 3 && seen.length <= 6, `${seen.length} pages in Where you'll see it`);
+ for (const [, href, title] of seen) {
+ const target = path.resolve(dir, href);
+ assert.ok(target.startsWith(ANIM + path.sep) && fs.existsSync(path.join(target, 'index.html')), `${href} is an animation page`);
+ assert.equal(title, h1Of(target), `${href} shows the page's title`);
+ }
+ });
+}