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: extend the guided-steps template for the Entrance & Exit rollout

matineb43fe237407
diff --git a/animations/02-entrance-and-exit/rotate-in/index.html b/animations/02-entrance-and-exit/rotate-in/index.html
index b757e311..c8e34306 100644
--- a/animations/02-entrance-and-exit/rotate-in/index.html
+++ b/animations/02-entrance-and-exit/rotate-in/index.html
@@ -34,7 +34,7 @@
<link rel="stylesheet" href="../../../assets/css/demo-page.css">
<script src="../../../assets/js/demo-page.js" defer></script>
</head>
-<body class="hb" data-hb-autoplay>
+<body class="hb" data-hb-kind="once" data-hb-autoplay>
<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="../bounce-in/" rel="prev" aria-label="Previous: Bounce In"><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>Bounce In</span></a></span>
diff --git a/assets/css/demo-page.css b/assets/css/demo-page.css
index ef80becf..72241b43 100644
--- a/assets/css/demo-page.css
+++ b/assets/css/demo-page.css
@@ -56,9 +56,12 @@ body.hb [hidden]{display:none!important}
/* Step 1: stage and player bar. 420px is roughly everything above and below the stage on the
first screen, so on a laptop the stage and the player bar are both visible on arrival.
The height is declared twice: browsers that know svh use the second, others keep the vh one. */
-.hb-page .stage{box-sizing:border-box;width:100%;min-width:0;min-height:0;margin:0;flex:none;
- height:clamp(300px,calc(100vh - 420px),440px);height:clamp(300px,calc(100svh - 420px),440px);
- border:1px solid rgba(255,255,255,.1);border-radius:12px;overflow:hidden}
+.hb-page .stage{box-sizing:border-box;width:100%;min-width:0;margin:0;flex:none;
+ height:var(--hb-stage-h,clamp(300px,calc(100vh - 420px),440px));height:var(--hb-stage-h,clamp(300px,calc(100svh - 420px),440px));
+ border:1px solid rgba(255,255,255,.1);border-radius:12px}
+/* Overflow belongs to the demo: this default has zero specificity, so a demo's own .stage rule wins
+ (scroll demos scroll inside their stage). A demo that needs another height sets --hb-stage-h or --hb-stage-h-phone. */
+:where(.hb-page .stage){min-height:0;overflow:hidden}
.hb-page .stage.hb-dots{background-image:radial-gradient(rgba(255,255,255,.075) 1px,transparent 1.5px);background-size:24px 24px;background-position:center}
.hb-player{display:flex;flex-wrap:wrap;align-items:center;gap:10px}
.hb-play,.hb-toggle{box-sizing:border-box;display:inline-flex;align-items:center;gap:10px;min-height:44px;padding:0 18px;
@@ -94,6 +97,16 @@ body.hb [hidden]{display:none!important}
.hb-options .hb-less,.hb-options[open] .hb-more-label{display:none}
.hb-options[open] .hb-less{display:inline}
.hb-options>.hb-settings{margin-top:16px}
+.hb-setting-top{display:flex;align-items:baseline;justify-content:space-between;gap:12px}
+.hb-value{font:600 15px/1.3 var(--hb-font);color:var(--hb-accent);white-space:nowrap}
+.hb-page .hb-setting input[type=range]{width:100%;min-height:44px;margin:0;accent-color:var(--hb-accent);cursor:pointer}
+.hb-select,.hb-text{box-sizing:border-box;width:100%;min-height:44px;padding:0 12px;border:1px solid var(--hb-edge);border-radius:8px;
+ background:var(--hb-panel);color:var(--hb-ink);font:500 16px/1.3 var(--hb-font)}
+textarea.hb-text{min-height:88px;padding:10px 12px;resize:vertical}
+.hb-page .swatches{display:flex;flex-wrap:wrap;gap:10px}
+.hb-page .swatches button{box-sizing:border-box;width:44px;height:44px;padding:0;border:2px solid transparent;border-radius:50%;
+ box-shadow:inset 0 0 0 1px rgba(255,255,255,.18);cursor:pointer}
+.hb-page .swatches button[aria-pressed="true"]{border-color:var(--hb-ink);box-shadow:inset 0 0 0 3px var(--hb-bg)}
/* Step 3: the prompt card */
.hb-card{display:flex;flex-direction:column;gap:20px;padding:clamp(18px,3vw,28px);border:1px solid rgba(255,255,255,.12);border-radius:12px;background:var(--hb-panel)}
@@ -139,6 +152,8 @@ body.hb [hidden]{display:none!important}
.hb-play:hover,.hb-toggle:hover,.hb-switch-row:hover{border-color:var(--hb-edge-2)}
.hb-page .seg button:hover{border-color:rgba(255,255,255,.34);color:var(--hb-ink)}
.hb-page .seg button.on:hover,.hb-page .seg button[aria-pressed="true"]:hover{border-color:var(--hb-accent);color:var(--hb-accent)}
+ .hb-page .swatches button:not([aria-pressed="true"]):hover{border-color:var(--hb-edge-2)}
+ .hb-select:hover,.hb-text:hover{border-color:var(--hb-edge-2)}
.hb-options>summary:hover,.hb-prompt-more:hover{color:color-mix(in srgb,var(--hb-accent) 70%,#fff)}
.hb-copy:hover{background:#fff}
.hb-rel:hover{border-color:color-mix(in srgb,var(--hb-accent) 55%,transparent)}
@@ -157,11 +172,13 @@ body.hb [hidden]{display:none!important}
.hb-lede{font-size:17px}
.hb-step-head h2{font-size:22px}
.hb-watch{gap:12px}
- .hb-page .stage{height:clamp(260px,calc(100vh - 330px),440px);height:clamp(260px,calc(100svh - 330px),440px)}
+ .hb-page .stage{height:var(--hb-stage-h,clamp(260px,calc(100vh - 330px),440px));height:var(--hb-stage-h,clamp(260px,calc(100svh - 330px),440px))}
}
@media(max-width:600px){
.hb-bar .hb-dir{display:none}
- .hb-page .stage{height:300px}
+ .hb-page .stage{height:var(--hb-stage-h-phone,300px)}
+ /* With both Previous and Next, phones show only the two chevrons; each link keeps its full name as its label */
+ .hb-pager:has(a + a) a > span{display:none}
.hb-step-head{gap:12px}
.hb-num{width:30px;height:30px;font-size:15px}
.hb-step-head p{font-size:15px}
diff --git a/assets/js/demo-page.js b/assets/js/demo-page.js
index 136fb38a..edf99a25 100644
--- a/assets/js/demo-page.js
+++ b/assets/js/demo-page.js
@@ -94,9 +94,15 @@
});
}
+ // Text squeezed onto one line and cut to max characters (ending with an ellipsis), for chips.
+ function shorten(text, max) {
+ var s = String(text).replace(/\s+/g, ' ').trim();
+ return s.length > max ? s.slice(0, max - 1).trimEnd() + '…' : s;
+ }
+
/* ---------- Page behaviour ---------- */
- var CONTROLS = 'input[type=range], input[type=checkbox], select, .seg, .swatches';
+ var CONTROLS = 'input[type=range], input[type=checkbox], input[type=text], textarea, select, .seg, .swatches';
function text(node) { return node ? node.textContent.replace(/\s+/g, ' ').trim() : ''; }
@@ -108,15 +114,18 @@
var wrap = control.closest('label');
if (wrap) return text(wrap);
var byFor = control.id && doc.querySelector('label[for="' + control.id + '"]');
- return byFor ? text(byFor) : '';
+ if (byFor) return text(byFor);
+ var setting = control.closest('.hb-setting');
+ return setting ? text(setting.querySelector('.hb-setting-name')) : '';
}
function valueFor(control) {
if (control.matches('input[type=range]')) {
- var row = control.closest('.sr');
- var shown = row && row.querySelector('.sv');
+ var setting = control.closest('.hb-setting');
+ var shown = setting && setting.querySelector('.hb-value');
return shown ? text(shown) : (control.getAttribute('aria-valuetext') || control.value);
}
+ if (control.matches('input[type=text], textarea')) return shorten(control.value, 40);
if (control.matches('input[type=checkbox]')) return control.checked ? 'on' : 'off';
if (control.matches('select')) return control.selectedOptions[0] ? text(control.selectedOptions[0]) : control.value;
var active = control.querySelector('.on, [aria-pressed="true"]');
@@ -138,7 +147,7 @@
return Array.prototype.filter.call(scope.querySelectorAll(CONTROLS), function (control) {
return isShown(control, scope, win);
}).map(function (control) {
- return { label: labelFor(doc, control), value: valueFor(control) };
+ return { label: labelFor(doc, control), value: valueFor(control), control: control };
});
}
@@ -195,6 +204,14 @@
chipsBox.hidden = !items.length;
}
+ // For page authors: a control without a label or a value is left out of the chips and the copied prompt.
+ function warnIncomplete() {
+ if (!tryStep || !win.console) return;
+ readSettings(doc, tryStep, win).forEach(function (s) {
+ if (!s.label || !s.value) win.console.warn('Your settings: this control has no ' + (s.label ? 'value' : 'label') + ' and is left out', s.control);
+ });
+ }
+
function setUpCopy() {
var label = copyBtn.querySelector('.hb-copy-label') || copyBtn;
var original = label.textContent;
@@ -296,12 +313,13 @@
}, 400);
}
refreshChips();
+ warnIncomplete();
loadReadme();
}
return {
escapeHtml: escapeHtml, plain: plain, isSafeHref: isSafeHref, inline: inline, sections: sections,
- paragraphs: paragraphs, seeAlso: seeAlso, settingsLine: settingsLine, markFill: markFill,
+ paragraphs: paragraphs, seeAlso: seeAlso, settingsLine: settingsLine, markFill: markFill, shorten: shorten,
readSettings: readSettings, boot: boot
};
});
diff --git a/index.html b/index.html
index 9209cc00..0875344d 100644
--- a/index.html
+++ b/index.html
@@ -924,7 +924,7 @@ const CATS=[
['blur-in','Blur In','Fades in while reducing blur — mimics camera focus pulling. Best on single hero elements.'],
['flip-in','Flip In','Rotates from a flat plane into view using CSS 3D perspective — perspective on the parent is the key.'],
['bounce-in','Bounce In','Overshoots final position then springs back — explicit @keyframes waypoints, not easing alone.'],
- ['rotate-in','Rotate In','Spins while entering — best on radially-symmetric shapes like icons, stars, and gears.'],
+ ['rotate-in','Rotate In','Spins into place while it grows. Best for icons, stars and badges.'],
]
},
{
diff --git a/tests/demo-page.test.js b/tests/demo-page.test.js
index 8ddaa027..74f59359 100644
--- a/tests/demo-page.test.js
+++ b/tests/demo-page.test.js
@@ -75,3 +75,10 @@ test('the module exports boot and readSettings without touching a DOM', () => {
assert.equal(typeof DP.boot, 'function');
assert.equal(typeof DP.readSettings, 'function');
});
+
+test('shorten squeezes whitespace and cuts long text with an ellipsis', () => {
+ assert.equal(DP.shorten(' Hello \n world ', 40), 'Hello world');
+ assert.equal(DP.shorten('abcdefghij', 5), 'abcd…');
+ assert.equal(DP.shorten('abc de', 5), 'abc…');
+ assert.equal(DP.shorten('', 5), '');
+});
diff --git a/tests/pages.test.js b/tests/pages.test.js
index 0e00938d..ba6bf665 100644
--- a/tests/pages.test.js
+++ b/tests/pages.test.js
@@ -19,6 +19,7 @@ const between = (s, from, to) => {
const end = s.indexOf(to, start + from.length);
return s.slice(start, end < 0 ? undefined : end);
};
+const decode = s => s.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
const demos = fs.readdirSync(ANIM, { withFileTypes: true }).filter(c => c.isDirectory()).flatMap(c =>
fs.readdirSync(path.join(ANIM, c.name), { withFileTypes: true }).filter(d => d.isDirectory())
@@ -26,6 +27,7 @@ const demos = fs.readdirSync(ANIM, { withFileTypes: true }).filter(c => c.isDire
const pageOf = d => read(path.join(d.dir, 'index.html'));
const converted = demos.filter(d => pageOf(d).includes('<main class="hb-view">'));
const steps = demos.filter(d => pageOf(d).includes('<main class="hb-page">'));
+const HOME = read(path.join(ROOT, 'index.html'));
const PILOT = '02-entrance-and-exit';
const PILOT_AUTOPLAY = new Set(['fade-in-out', 'slide-in', 'slide-up-reveal', 'scale-in', 'clip-path-reveal',
@@ -71,7 +73,9 @@ for (const d of steps) {
const html = pageOf(d);
assert.ok(html.includes('<link rel="stylesheet" href="../../../assets/css/demo-page.css">'), 'page stylesheet');
assert.ok(html.includes('<script src="../../../assets/js/demo-page.js" defer></script>'), 'page script');
- assert.match(html, /<body class="hb"( data-hb-autoplay)?>/);
+ const body = html.match(/<body class="hb" data-hb-kind="(once|loop|scroll|do)"( data-hb-autoplay)?>/);
+ assert.ok(body, 'the body declares the page kind');
+ const kind = body[1];
for (const old of ['handbook.css', 'handbook.js', 'hb-view', 'hb-side', 'hb-take', 'ah-bar', 'Copy source', 'Read more',
'class="note"', 'class="kv"', 'class="lbl"', 'class="btn-row"', 'Bricolage', 'PlexMono']) {
assert.ok(!html.includes(old), `old markup left: ${old}`);
@@ -89,8 +93,10 @@ for (const d of steps) {
assert.ok(prompt.trim().endsWith('Match the settings listed below.'), 'prompt ending');
assert.ok(!prompt.includes('`'), 'prompt contains no code');
const player = between(html, '<div class="hb-player">', '</div>');
- assert.equal(count(html, 'data-hb-replay'), 1, 'one Replay control');
- assert.ok(player.includes('data-hb-replay'), 'Replay is in the player bar');
+ if (kind === 'once') {
+ assert.equal(count(html, 'data-hb-replay'), 1, 'one Replay control');
+ assert.ok(player.includes('data-hb-replay'), 'Replay is in the player bar');
+ }
for (const marker of ['data-hb-loop', 'data-hb-slowmo']) {
assert.ok(count(html, marker) <= 1, `at most one ${marker}`);
assert.equal(count(player, marker), count(html, marker), `${marker} is in the player bar`);
@@ -111,6 +117,36 @@ for (const d of steps) {
}
});
+ test(`${d.slug}: every setting has a label and every choice group has one choice made`, () => {
+ const tryIt = between(pageOf(d), '<section class="hb-step hb-try"', '<section class="hb-step hb-prompt-step"');
+ for (const [, cls, attrs, inner] of tryIt.matchAll(/<div class="(seg|swatches)"([^>]*)>([\s\S]*?)<\/div>/g)) {
+ const labelledBy = (attrs.match(/aria-labelledby="([^"]+)"/) || [])[1];
+ assert.ok(/role="group"/.test(attrs), `a ${cls} group has role="group"`);
+ assert.ok(labelledBy && tryIt.includes(`id="${labelledBy}"`), `a ${cls} group is labelled`);
+ assert.equal(count(inner, 'aria-pressed="true"'), 1, `${labelledBy} has exactly one choice made`);
+ }
+ for (const [, name, attrs] of tryIt.matchAll(/<(input|select|textarea)\b([^>]*)>/g)) {
+ if (/type="checkbox"/.test(attrs)) continue;
+ const id = (attrs.match(/\sid="([^"]+)"/) || [])[1];
+ assert.ok(id && new RegExp(`<label[^>]*\\sfor="${id}"`).test(tryIt), `${name} ${id || '(no id)'} has a label`);
+ }
+ assert.equal(count(tryIt, 'type="checkbox"'), count(tryIt, 'class="hb-switch-row"'), 'every switch sits in a labelled switch row');
+ });
+
+ test(`${d.slug}: README is ready for the site`, () => {
+ const s = sections(read(path.join(d.dir, 'README.md')));
+ for (const h of ['What it is', 'When to use it', 'Key parameters', 'See also']) assert.ok(s[h], `section ${h}`);
+ assert.ok(!s['What it is'].includes('`'), 'What it is has no code');
+ assert.ok(!s['Key parameters'].includes('`'), 'Key parameters has no code');
+ assert.ok(table(s['Key parameters']).length > 0, 'Key parameters has rows');
+ const links = [...s['See also'].matchAll(/^\s*[-*]\s+\[[^\]]+\]\(([^)\s]+)\)(.*)$/gm)];
+ assert.ok(links.length > 0, 'See also has links');
+ for (const [, href, rest] of links) {
+ assert.ok(isDemoDir(path.resolve(d.dir, href)), `See also link ${href}`);
+ assert.match(rest, /^\s*[—–-]\s*\S/, `See also ${href} has a short description`);
+ }
+ });
+
test(`${d.slug}: every Key parameters name is a setting in Try it`, () => {
const tryIt = between(pageOf(d), '<section class="hb-step hb-try"', '<section class="hb-step hb-prompt-step"')
.replace(/<[^>]+>/g, ' ');
@@ -120,26 +156,27 @@ for (const d of steps) {
if (name) assert.ok(tryIt.includes(name), `setting "${name}"`);
}
});
-}
-const PILOT_SLUGS = ['fade-in-out', 'slide-in', 'slide-up-reveal', 'scale-in', 'clip-path-reveal', 'curtain-reveal',
- 'split-text-reveal', 'letter-by-letter-stagger', 'word-by-word-reveal', 'blur-in', 'flip-in', 'bounce-in', 'rotate-in'];
+ test(`${d.slug}: the home page card uses the page's description`, () => {
+ const lede = decode(pageOf(d).match(/<p class="hb-lede">([^<]*)<\/p>/)[1]);
+ const entry = HOME.match(new RegExp(`\\['${d.slug}','(?:[^'\\\\]|\\\\.)*','((?:[^'\\\\]|\\\\.)*)'\\]`));
+ assert.ok(entry, 'home page entry');
+ assert.equal(entry[1].replace(/\\'/g, "'"), lede);
+ });
+}
-for (const slug of PILOT_SLUGS) {
- test(`README for ${slug} is ready for the site`, () => {
- const dir = path.join(ANIM, PILOT, slug);
- const s = sections(read(path.join(dir, 'README.md')));
+for (const d of converted.filter(c => c.cat === PILOT)) {
+ test(`README for ${d.slug} is ready for the site`, () => {
+ const s = sections(read(path.join(d.dir, 'README.md')));
for (const h of ['What it is', 'When to use it', 'Key parameters', 'See also']) assert.ok(s[h], `section ${h}`);
assert.ok(!s['What it is'].includes('`'), 'What it is has no code');
assert.ok(!s['Key parameters'].includes('`'), 'Key parameters has no code');
assert.ok(table(s['Key parameters']).length > 0, 'Key parameters has rows');
for (const [, href] of s['See also'].matchAll(/\]\(([^)\s]+)\)/g)) {
- assert.ok(isDemoDir(path.resolve(dir, href)), `See also link ${href}`);
+ assert.ok(isDemoDir(path.resolve(d.dir, href)), `See also link ${href}`);
}
});
-}
-for (const d of converted.filter(c => c.cat === PILOT)) {
test(`${d.slug}: every Key parameters name is a control on the page`, () => {
const html = pageOf(d);
const panel = html.slice(html.indexOf('<section class="hb-settings"'), html.indexOf('<div class="hb-take">')).replace(/<[^>]+>/g, ' ');
@@ -152,9 +189,8 @@ for (const d of converted.filter(c => c.cat === PILOT)) {
}
test('the home page uses Schibsted Grotesk and the new intro line', () => {
- const html = read(path.join(ROOT, 'index.html'));
- assert.ok(html.includes("url('assets/fonts/schibsted-latin.woff2')"), 'Latin font file');
- assert.ok(html.includes("url('assets/fonts/schibsted-latin-ext.woff2')"), 'Latin Extended font file');
- for (const old of ['Bricolage', 'PlexMono', 'var(--mono)', '--mono:']) assert.ok(!html.includes(old), `still uses ${old}`);
- assert.ok(html.includes('See 129 web animations move, learn when to use each one, and copy a prompt to build it.'));
+ assert.ok(HOME.includes("url('assets/fonts/schibsted-latin.woff2')"), 'Latin font file');
+ assert.ok(HOME.includes("url('assets/fonts/schibsted-latin-ext.woff2')"), 'Latin Extended font file');
+ for (const old of ['Bricolage', 'PlexMono', 'var(--mono)', '--mono:']) assert.ok(!HOME.includes(old), `still uses ${old}`);
+ assert.ok(HOME.includes('See 129 web animations move, learn when to use each one, and copy a prompt to build it.'));
});