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.

fix: the Learn tests check what the visitor sees (each step's number, kind and line, and the lists with their role), accept a first and last lesson with no Previous or Next link, need the home page's version before comparing it, and check every Learn page's tab title, descriptions and address; the Learn page's tab title matches its heading, its lists keep their list role, its numbers are 44px and an idea not built yet is outlined instead of filled

matind5cc860136de
diff --git a/learn/index.html b/learn/index.html
index 43de43f9..d92f6a93 100644
--- a/learn/index.html
+++ b/learn/index.html
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Learn Web Animation — Animation Handbook</title>
+ <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">
@@ -11,12 +11,12 @@
<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: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: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>
@@ -27,9 +27,10 @@
.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%;
+ .hb-path .n{grid-row:1/span 3;display:flex;align-items:center;justify-content:center;box-sizing:border-box;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 [data-soon] .n{border-color:var(--hb-edge);background:none;color:var(--hb-muted)}
.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)}
@@ -54,7 +55,7 @@
<section class="hb-chapter" aria-labelledby="ch-1">
<h2 id="ch-1"><span>Chapter 1</span>Appear and leave</h2>
- <ol class="hb-path">
+ <ol class="hb-path" role="list">
<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>
@@ -65,7 +66,7 @@
<section class="hb-chapter" aria-labelledby="ch-2">
<h2 id="ch-2"><span>Chapter 2</span>Answer the visitor</h2>
- <ol class="hb-path">
+ <ol class="hb-path" role="list">
<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>
@@ -76,7 +77,7 @@
<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">
+ <ol class="hb-path" role="list">
<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>
@@ -87,7 +88,7 @@
<section class="hb-chapter" aria-labelledby="ch-4">
<h2 id="ch-4"><span>Chapter 4</span>Change pages</h2>
- <ol class="hb-path">
+ <ol class="hb-path" role="list">
<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>
@@ -98,7 +99,7 @@
<section class="hb-chapter" aria-labelledby="ch-5">
<h2 id="ch-5"><span>Chapter 5</span>Depth and 3D</h2>
- <ol class="hb-path">
+ <ol class="hb-path" role="list">
<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>
diff --git a/tests/learn.test.js b/tests/learn.test.js
index 06a621df..7daf6f8e 100644
--- a/tests/learn.test.js
+++ b/tests/learn.test.js
@@ -14,23 +14,44 @@ 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 }.
+// The steps of the path in page order: { n, kind, soon, href (null while not built), title, num, label, line, body }.
+// num, label and line are what the visitor reads on the step: its number, its kind and its one line.
+const spanOf = (body, cls) => (body.match(new RegExp(`<span class="${cls}">([^<]*)</span>`)) || [])[1];
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] };
+ return { n: Number(m[1]), kind: m[2], soon: !!m[3], href: link ? link[1] : null, title: (m[4].match(/<b>([^<]+)<\/b>/) || [])[1],
+ num: spanOf(m[4], 'n'), label: spanOf(m[4], 'k'), line: spanOf(m[4], 'line'), 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));
+// Every Learn page: the hub and each idea lesson.
+const PAGES = [path.join(LEARN, 'index.html'), ...LESSONS.map(d => path.join(d, 'index.html'))];
+const decode = s => s.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
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]);
+ const chapters = [...HUB.matchAll(/<section class="hb-chapter"[\s\S]*?<\/section>/g)].map(m => m[0]);
+ assert.deepEqual(chapters.map(c => count(c, '<li data-step=')), [5, 5, 5, 5, 5]);
+ // Each chapter is one ordered list. VoiceOver drops the list role when the list has no bullets, so the role is written out.
+ for (const [i, c] of chapters.entries()) {
+ assert.equal(count(c, '<ol class="hb-path"'), 1, `chapter ${i + 1} is an ordered list`);
+ assert.equal(count(c, '<ol class="hb-path" role="list">'), 1, `chapter ${i + 1}'s list keeps its list role`);
+ }
+});
+
+test('every step shows its own number, its kind (Idea, Animation, or Idea · Not built yet) and a line', () => {
+ for (const s of STEPS) {
+ assert.equal(s.num, String(s.n), `step ${s.n} shows its own number`);
+ assert.ok(!s.soon || s.kind === 'idea', `step ${s.n}: only an idea can be not built yet`);
+ const label = s.soon ? 'Idea · Not built yet' : s.kind === 'idea' ? 'Idea' : 'Animation';
+ assert.equal(s.label, label, `step ${s.n} shows its kind`);
+ assert.ok(s.line && s.line.trim(), `step ${s.n} has its line`);
+ }
});
test('every built step links to an existing page and shows its title; a step not built yet has no link and says so', () => {
@@ -81,6 +102,7 @@ for (const { step, dir } of onPath) {
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: ([^"]+)">`));
+ if (!other) { assert.equal(a, null, `no top bar ${rel} link at the end of the path`); continue; }
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}`);
@@ -89,7 +111,7 @@ for (const { step, dir } of onPath) {
});
}
-for (const file of [path.join(LEARN, 'index.html'), ...LESSONS.map(d => path.join(d, 'index.html'))]) {
+for (const file of PAGES) {
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);
@@ -99,13 +121,39 @@ for (const file of [path.join(LEARN, 'index.html'), ...LESSONS.map(d => path.joi
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`);
+ // The home page links only demo-page.js (it has its own styles), so its version N is the script's. Without a version on the
+ // home page the comparison below could pass with nothing on either side.
+ const homeVersion = version(HOME, 'js');
+ assert.ok(homeVersion, 'the home page links demo-page.js with a version');
+ for (const f of ['css', 'js']) assert.equal(version(html, f), homeVersion, `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');
});
}
+// What search engines, social sites and the browser tab show, as on every animation page: the tab title is the heading and the site
+// name, the descriptions are the lede, and the address is the page's own folder.
+for (const file of PAGES) {
+ const name = path.relative(ROOT, file).split(path.sep).join('/');
+ test(`${name}: the tab title, the descriptions and the address say what the page says`, () => {
+ const html = read(file);
+ const h1 = decode((html.match(/<h1>([^<]+)<\/h1>/) || [])[1] || '');
+ const lede = decode(((html.match(/<p class="hb-lede">([\s\S]*?)<\/p>/) || [])[1] || '').replace(/<[^>]+>/g, '')).replace(/\s+/g, ' ').trim();
+ assert.ok(h1, 'the page has a heading');
+ assert.ok(lede, 'the page has a lede');
+ const meta = attr => { const m = html.match(new RegExp(`<meta ${attr} content="([^"]*)">`)); assert.ok(m, `<meta ${attr}> is there`); return decode(m[1]); };
+ const title = `${h1} — Animation Handbook`;
+ assert.equal(decode((html.match(/<title>([^<]*)<\/title>/) || [])[1] || ''), title, '<title> is the heading and the site name');
+ for (const attr of ['property="og:title"', 'name="twitter:title"']) assert.equal(meta(attr), title, attr);
+ for (const attr of ['name="description"', 'property="og:description"', 'name="twitter:description"']) assert.equal(meta(attr), lede, `${attr} is the lede`);
+ const address = `https://matinmonshizadeh.github.io/animation-handbook/${path.relative(ROOT, path.dirname(file)).split(path.sep).join('/')}/`;
+ const canonical = html.match(/<link rel="canonical" href="([^"]*)">/);
+ assert.ok(canonical, 'the canonical link is there');
+ assert.equal(canonical[1], address, 'the canonical address is the live address of the page\'s folder');
+ assert.equal(meta('property="og:url"'), address, 'og:url is the live address of the page\'s folder');
+ });
+}
+
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>'));