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
fix: a scroll page can say in its own words what reduced motion does there, and five pages where it turns the effect off now do
matin199f67270250
diff --git a/animations/01-scroll-based/parallax-depth-of-field/index.html b/animations/01-scroll-based/parallax-depth-of-field/index.htmlindex 01b2f42f..bc04b498 100644--- a/animations/01-scroll-based/parallax-depth-of-field/index.html+++ b/animations/01-scroll-based/parallax-depth-of-field/index.html@@ -38,7 +38,7 @@<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=5"><script src="../../../assets/js/demo-page.js?v=5" defer></script></head>-<body class="hb" data-hb-kind="scroll" data-hb-autoplay>+<body class="hb" data-hb-kind="scroll" data-hb-autoplay data-hb-motion-note="The layers stay still and only the focus follows the scroll"><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="../parallax-scrolling/" rel="next" aria-label="Next: Parallax Scrolling"><span><span class="hb-dir">Next: </span>Parallax Scrolling</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>diff --git a/animations/01-scroll-based/parallax-scrolling/index.html b/animations/01-scroll-based/parallax-scrolling/index.htmlindex 0d696c61..1e17128e 100644--- a/animations/01-scroll-based/parallax-scrolling/index.html+++ b/animations/01-scroll-based/parallax-scrolling/index.html@@ -39,7 +39,7 @@<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=5"><script src="../../../assets/js/demo-page.js?v=5" defer></script></head>-<body class="hb" data-hb-kind="scroll" data-hb-autoplay>+<body class="hb" data-hb-kind="scroll" data-hb-autoplay data-hb-motion-note="The layers stay still while the box scrolls"><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="../parallax-depth-of-field/" rel="prev" aria-label="Previous: Parallax Depth-of-Field"><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>Parallax Depth-of-Field</span></a><a href="../reverse-scrolling-columns/" rel="next" aria-label="Next: Reverse-Scrolling Columns"><span><span class="hb-dir">Next: </span>Reverse-Scrolling Columns</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>diff --git a/animations/01-scroll-based/reverse-scrolling-columns/index.html b/animations/01-scroll-based/reverse-scrolling-columns/index.htmlindex d7326896..73fb55a1 100644--- a/animations/01-scroll-based/reverse-scrolling-columns/index.html+++ b/animations/01-scroll-based/reverse-scrolling-columns/index.html@@ -49,7 +49,7 @@<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=5"><script src="../../../assets/js/demo-page.js?v=5" defer></script></head>-<body class="hb" data-hb-kind="scroll" data-hb-autoplay>+<body class="hb" data-hb-kind="scroll" data-hb-autoplay data-hb-motion-note="The columns stay still while the box scrolls"><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="../parallax-scrolling/" rel="prev" aria-label="Previous: Parallax Scrolling"><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>Parallax Scrolling</span></a><a href="../cover-card-to-fixed-header/" rel="next" aria-label="Next: Cover Card to Fixed Header"><span><span class="hb-dir">Next: </span>Cover Card to Fixed Header</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>diff --git a/animations/01-scroll-based/scroll-velocity-skew/index.html b/animations/01-scroll-based/scroll-velocity-skew/index.htmlindex c170850f..76f14cf2 100644--- a/animations/01-scroll-based/scroll-velocity-skew/index.html+++ b/animations/01-scroll-based/scroll-velocity-skew/index.html@@ -37,7 +37,7 @@<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=5"><script src="../../../assets/js/demo-page.js?v=5" defer></script></head>-<body class="hb" data-hb-kind="scroll" data-hb-autoplay>+<body class="hb" data-hb-kind="scroll" data-hb-autoplay data-hb-motion-note="The rows stay straight however fast the box scrolls"><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="../text-fill-on-scroll/" rel="prev" aria-label="Previous: Text Fill on Scroll"><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>Text Fill on Scroll</span></a><a href="../svg-line-draw/" rel="next" aria-label="Next: SVG Line Draw on Scroll"><span><span class="hb-dir">Next: </span>SVG Line Draw on Scroll</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>diff --git a/animations/01-scroll-based/zoom-into-image/index.html b/animations/01-scroll-based/zoom-into-image/index.htmlindex 9da2ae70..86cfbac9 100644--- a/animations/01-scroll-based/zoom-into-image/index.html+++ b/animations/01-scroll-based/zoom-into-image/index.html@@ -43,7 +43,7 @@<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=5"><script src="../../../assets/js/demo-page.js?v=5" defer></script></head>-<body class="hb" data-hb-kind="scroll" data-hb-autoplay>+<body class="hb" data-hb-kind="scroll" data-hb-autoplay data-hb-motion-note="The whole picture and its caption show from the start"><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="../section-wipe/" rel="prev" aria-label="Previous: Section Wipe"><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>Section Wipe</span></a><a href="../scroll-image-sequence/" rel="next" aria-label="Next: Scroll Image Sequence"><span><span class="hb-dir">Next: </span>Scroll Image Sequence</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>diff --git a/assets/js/demo-page.js b/assets/js/demo-page.jsindex 651db7f7..ef83f7b0 100644--- a/assets/js/demo-page.js+++ b/assets/js/demo-page.js@@ -111,11 +111,12 @@}// The reduced-motion note for the player bar, from what the bar holds ({ loop, slow, pause } as booleans) and whether the- // page is a scroll page ({ scroll }); '' when reduced motion changes nothing there.+ // page is a scroll page ({ scroll }: true, or the page's own sentence when reduced motion does something other than take the+ // animation out of it); '' when reduced motion changes nothing there.function motionNote(has) {var off = [has.loop && 'Loop', has.slow && 'Slow motion'].filter(Boolean);var parts = [];- if (has.scroll) parts.push('The effects follow the scroll without animating');+ if (has.scroll) parts.push(typeof has.scroll === 'string' ? has.scroll : 'The effects follow the scroll without animating');if (has.pause) parts.push('It starts paused');if (off.length) parts.push(off.join(' and ') + (off.length > 1 ? ' are' : ' is') + ' off');return parts.length ? parts.join(' and ') + ' because your device is set to reduce motion.' : '';@@ -427,7 +428,9 @@// 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. A scroll page has nothing to- // switch off, and its note says that the effects follow the scroll without animating.+ // switch off, and its note says that the effects follow the scroll without animating. A page where reduced motion turns+ // an effect off instead says so with data-hb-motion-note on the body: one sentence with no full stop, which the note+ // then ends with "because your device is set to reduce motion." Only a scroll page reads it.var playerSwitches = [loopCtl, slowCtl].filter(Boolean);var noteEl = null;function followReducedMotion() {@@ -439,7 +442,9 @@if (label) label.classList.toggle('is-disabled', reduced);});if (reduced && pauseCtl && !paused) setPaused(true);- var note = reduced ? motionNote({ loop: !!loopCtl, slow: !!slowCtl, pause: !!pauseCtl, scroll: doc.body.getAttribute('data-hb-kind') === 'scroll' }) : '';+ var kind = doc.body.getAttribute('data-hb-kind');+ var note = reduced ? motionNote({ loop: !!loopCtl, slow: !!slowCtl, pause: !!pauseCtl,+ scroll: kind === 'scroll' && (doc.body.getAttribute('data-hb-motion-note') || true) }) : '';if (note && !noteEl && player) {noteEl = doc.createElement('p');noteEl.className = 'hb-player-note';diff --git a/tests/demo-page.test.js b/tests/demo-page.test.jsindex 6f8d9207..898c37ce 100644--- a/tests/demo-page.test.js+++ b/tests/demo-page.test.js@@ -99,13 +99,14 @@ test('motionNote says what reduced motion changes in the player bar', () => {assert.equal(DP.motionNote({ pause: true, slow: true }), 'It starts paused and Slow motion is off because your device is set to reduce motion.');assert.equal(DP.motionNote({ pause: true }), 'It starts paused because your device is set to reduce motion.');assert.equal(DP.motionNote({ scroll: true }), 'The effects follow the scroll without animating because your device is set to reduce motion.');+ assert.equal(DP.motionNote({ scroll: 'The layers stay still while the box scrolls' }), 'The layers stay still while the box scrolls because your device is set to reduce motion.');assert.equal(DP.motionNote({}), '');});// boot() takes the document and window it works on, so a stand-in page with just enough DOM can stand for a real one. It holds// a stage and, by kind, the buttons boot() looks for. Events are sent to the stage by hand (with isTrusted set as a browser// would), timers wait in a list until the test runs them, and every hb:input the script sends is kept.-function standInPage(kind, reduced) {+function standInPage(kind, reduced, bodyAttributes) {const timers = [], sent = [];const node = () => ({attrs: {}, handlers: {}, children: [], clicks: 0, textContent: '', innerHTML: '', classList: { add() {}, remove() {}, toggle() {} },@@ -125,6 +126,7 @@ function standInPage(kind, reduced) {const body = node();body.setAttribute('data-hb-kind', kind);body.setAttribute('data-hb-autoplay', '');+ Object.keys(bodyAttributes || {}).forEach(name => body.setAttribute(name, bodyAttributes[name]));const doc = { body, querySelector: selector => (selector === '.hb-page' ? page : null), createElement: node, dispatchEvent: event => sent.push(event) };const win = {matchMedia: () => ({ matches: !!reduced, addEventListener() {} }),@@ -186,3 +188,16 @@ test('reduced motion adds no note to a scroll page that is not set to reduce motassert.equal(standInPage('scroll', false).player.children.length, 0);assert.equal(standInPage('do', true).player.children.length, 0);});++test('a scroll page can say in its own words what reduced motion does there', () => {+ const page = standInPage('scroll', true, { 'data-hb-motion-note': 'The layers stay still while the box scrolls' });+ assert.deepEqual(page.player.children.map(c => [c.className, c.textContent]),+ [['hb-player-note', 'The layers stay still while the box scrolls because your device is set to reduce motion.']]);+});++test('a scroll page with an empty sentence of its own gets the usual note, and only a scroll page reads the sentence', () => {+ const usual = 'The effects follow the scroll without animating because your device is set to reduce motion.';+ assert.deepEqual(standInPage('scroll', true, { 'data-hb-motion-note': '' }).player.children.map(c => c.textContent), [usual]);+ assert.equal(standInPage('do', true, { 'data-hb-motion-note': 'The layers stay still while the box scrolls' }).player.children.length, 0);+ assert.equal(standInPage('scroll', false, { 'data-hb-motion-note': 'The layers stay still while the box scrolls' }).player.children.length, 0);+});diff --git a/tests/pages.test.js b/tests/pages.test.jsindex 392e5661..e5c0ec44 100644--- a/tests/pages.test.js+++ b/tests/pages.test.js@@ -120,9 +120,15 @@ for (const d of steps) {// The shared files carry a version so visitors do not get a cached older copy after publishing.assert.match(html, /<link rel="stylesheet" href="\.\.\/\.\.\/\.\.\/assets\/css\/demo-page\.css\?v=\d+">/, 'page stylesheet');assert.match(html, /<script src="\.\.\/\.\.\/\.\.\/assets\/js\/demo-page\.js\?v=\d+" defer><\/script>/, 'page script');- const body = html.match(/<body class="hb" data-hb-kind="(once|loop|scroll|do)"( data-hb-autoplay)?>/);+ const body = html.match(/<body class="hb" data-hb-kind="(once|loop|scroll|do)"( data-hb-autoplay)?(?: data-hb-motion-note="([^"]*)")?>/);assert.ok(body, 'the body declares the page kind');const kind = body[1];+ // A scroll page where reduced motion turns an effect off says so in its own words; the shared script ends the note with+ // " because your device is set to reduce motion.", so the sentence starts with a capital letter and has no full stop.+ if (body[3] !== undefined) {+ assert.equal(kind, 'scroll', 'only a scroll page has data-hb-motion-note');+ assert.match(body[3], /^[A-Z][^.]*[^.\s]$/, 'data-hb-motion-note is one sentence with no full stop');+ }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}`);