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
feat: support do-it demos with Show me and Reset
matin70cd7ca965cb
diff --git a/assets/css/demo-page.css b/assets/css/demo-page.cssindex 4667b179..d32f0292 100644--- a/assets/css/demo-page.css+++ b/assets/css/demo-page.css@@ -215,6 +215,8 @@ textarea.hb-text{min-height:88px;padding:10px 12px;resize:vertical}.hb-player{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}.hb-play,.hb-player-note{grid-column:1/-1}.hb-player:has(> [data-hb-pause] + .hb-toggle) > .hb-play{grid-column:auto}+ /* Two buttons in the player bar (Show me and Reset, Play and Back to top) share one row */+ .hb-player:has(> .hb-play + .hb-play) > .hb-play{grid-column:auto}.hb-play,.hb-toggle{justify-content:center;gap:8px;padding:0 12px;font-size:14px}.hb-page .seg button{flex:1 0 auto;padding:0 10px}.hb-prompt{font-size:16px;line-height:1.6}diff --git a/assets/js/demo-page.js b/assets/js/demo-page.jsindex 92ceb630..989267c4 100644--- a/assets/js/demo-page.js+++ b/assets/js/demo-page.js@@ -1,8 +1,9 @@/* Animation Handbook — shared behaviour for the guided-steps demo pages.* Fills in "Your settings", Copy prompt, the README's "What it is" and "Similar* animations", plays the demo on arrival, replays it when a setting changes, runs- * Pause and CSS slow motion on loop pages, and follows reduced motion (Loop and- * Slow motion greyed out, loops start paused).+ * Pause and CSS slow motion on loop pages, presses Show me on do-it pages and tells+ * the page when the visitor takes over ("hb:input"), and follows reduced motion+ * (Loop and Slow motion greyed out, loops start paused).* The pure helpers are exported for tests/demo-page.test.js. */(function (root, factory) {var api = factory();@@ -184,6 +185,7 @@var pauseCtl = page.querySelector('[data-hb-pause]');var stage = page.querySelector('.stage');var player = page.querySelector('.hb-player');+ var demoCtl = page.querySelector('[data-hb-demo]');var reduce = win.matchMedia ? win.matchMedia('(prefers-reduced-motion: reduce)') : null;var promptText = text(promptEl);@@ -344,6 +346,16 @@if (slowing) win.requestAnimationFrame(slowStage);}+ // Do-it pages: the visitor's own press, key, wheel or touch inside the stage is sent as "hb:input", so the page+ // can stop a Show me run that is under way and leave the visitor in control.+ function setUpVisitorInput() {+ ['pointerdown', 'keydown', 'wheel', 'touchstart'].forEach(function (type) {+ stage.addEventListener(type, function (e) {+ if (e.isTrusted) doc.dispatchEvent(new win.CustomEvent('hb:input', { detail: { type: type } }));+ }, { capture: true, passive: true });+ });+ }+// While the device asks for reduced motion, Loop and Slow motion are switched off and cannot be switched on, a// loop starts paused, and a note in the player bar says why. Replay and Play still work.var playerSwitches = [loopCtl, slowCtl].filter(Boolean);@@ -374,6 +386,7 @@if (tryStep) ['input', 'change', 'click'].forEach(function (type) { tryStep.addEventListener(type, onSettingsChange); });if (slowCtl) slowCtl.addEventListener('change', replay);if (pauseCtl) pauseCtl.addEventListener('click', function () { setPaused(!paused); });+ if (demoCtl && stage) setUpVisitorInput();if (slowCtl && stage && stage.getAnimations && slowCtl.getAttribute('data-hb-slowmo') === 'css') {slowCtl.addEventListener('change', function () { if (!slowing) slowStage(); });if (slowCtl.checked) slowStage();@@ -383,6 +396,7 @@else if (reduce && reduce.addListener) reduce.addListener(followReducedMotion);if (doc.body.hasAttribute('data-hb-autoplay')) {win.setTimeout(function () {+ if (demoCtl) { if (!(reduce && reduce.matches)) demoCtl.click(); return; }if (loopCtl && !(reduce && reduce.matches)) {// After Back or a reload a browser can bring Loop back already on; press Replay so the demo still starts.if (loopCtl.checked) replay();diff --git a/tests/pages.test.js b/tests/pages.test.jsindex b6742f3f..07f8626b 100644--- a/tests/pages.test.js+++ b/tests/pages.test.js@@ -101,7 +101,16 @@ for (const d of steps) {assert.equal(count(html, 'data-hb-replay') + count(html, 'data-hb-loop') + count(html, 'data-hb-autoplay'), 0,'a loop has no Replay, Loop or autoplay');}- for (const marker of ['data-hb-loop', 'data-hb-slowmo', 'data-hb-pause']) {+ if (kind === 'do') {+ assert.equal(count(html, 'data-hb-demo'), 1, 'one Show me control');+ assert.ok(player.includes('<button class="hb-play" type="button" id="btn-demo" data-hb-demo>'), 'Show me is in the player bar');+ assert.ok(count(html, 'data-hb-reset') <= 1 && count(player, 'data-hb-reset') === count(html, 'data-hb-reset'),+ 'at most one Reset, in the player bar');+ for (const other of ['data-hb-replay', 'data-hb-loop', 'data-hb-pause', 'data-hb-autoscroll', 'data-hb-top']) {+ assert.equal(count(html, other), 0, `a do-it page has no ${other}`);+ }+ }+ for (const marker of ['data-hb-loop', 'data-hb-slowmo', 'data-hb-pause', 'data-hb-demo', 'data-hb-reset']) {assert.ok(count(html, marker) <= 1, `at most one ${marker}`);assert.equal(count(player, marker), count(html, marker), `${marker} is in the player bar`);const input = (html.match(new RegExp(`<input[^>]*${marker}[^>]*>`)) || [''])[0];diff --git a/tools/check-pages.mjs b/tools/check-pages.mjsindex aa2d39e7..1d22f593 100644--- a/tools/check-pages.mjs+++ b/tools/check-pages.mjs@@ -8,8 +8,11 @@// hb-check in the temp folder (emptied at the start of each run). Console warnings count as problems too (the page// script warns about settings that have no label or value). On plays-once pages the desktop run also checks that// Replay and a setting change visibly move the stage; on loop pages it checks that the stage moves, that Pause stops-// it and Play starts it again (twice over), and the reduced-motion run checks that the loop starts paused. The 320px-// phone runs the page checks (overflow, small targets, chips, README) and takes screenshots, and nothing more.+// it and Play starts it again (twice over), and the reduced-motion run checks that the loop starts paused. On do-it+// pages the desktop and reduced-motion runs press Show me and check that it visibly moves the stage (the desktop run+// waits for the run on arrival to end first), and the reduced-motion run checks that nothing moves before it is+// pressed. The 320px phone runs the page checks (overflow, small targets, chips, README) and takes screenshots, and+// nothing more.// Exit code 1 on any problem.import { spawn } from 'node:child_process';import { existsSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';@@ -244,6 +247,21 @@ async function loopProblems(reduced) {return problems;}+// Do-it pages: Show me must visibly move the stage within 1.6 s, and under reduced motion the page must not move by+// itself. Show me runs on arrival, so the desktop check first waits for that run to end.+async function demoProblems(reduced) {+ if (!(await evaluate(`!!document.querySelector('[data-hb-demo]')`))) return ['no Show me button to check'];+ const problems = [];+ if (reduced && await stageChanges(1500)) problems.push('the stage moves by itself under reduced motion');+ if (!reduced) await sleep(5000);+ const rest = await stageShot();+ await evaluate(`document.querySelector('[data-hb-demo]').click()`);+ let moved = false;+ for (let i = 0; i < 8 && !moved; i++) { await sleep(200); moved = (await stageShot()) !== rest; }+ if (!moved) problems.push('Show me does not visibly move the stage');+ return problems;+}+let failures = 0;try {ws = new WebSocket(await pageSocket());@@ -309,6 +327,7 @@ try {}if (setup.moves && !setup.reduce && result.kind === 'once') problems.push(...await movementProblems());if (result.kind === 'loop' && (setup.moves || setup.reduce)) problems.push(...await loopProblems(!!setup.reduce));+ if (result.kind === 'do' && (setup.moves || setup.reduce)) problems.push(...await demoProblems(!!setup.reduce));} catch (err) {problems.push(`check failed: ${err.message}`);}