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: watch longer for a paused loop and check the whole Pause button

matin2e005abe0553
diff --git a/assets/js/demo-page.js b/assets/js/demo-page.js
index 2119a952..92ceb630 100644
--- a/assets/js/demo-page.js
+++ b/assets/js/demo-page.js
@@ -376,6 +376,7 @@
if (pauseCtl) pauseCtl.addEventListener('click', function () { setPaused(!paused); });
if (slowCtl && stage && stage.getAnimations && slowCtl.getAttribute('data-hb-slowmo') === 'css') {
slowCtl.addEventListener('change', function () { if (!slowing) slowStage(); });
+ if (slowCtl.checked) slowStage();
}
followReducedMotion();
if (reduce && reduce.addEventListener) reduce.addEventListener('change', followReducedMotion);
diff --git a/tests/pages.test.js b/tests/pages.test.js
index 3da22d3c..41b3fa4b 100644
--- a/tests/pages.test.js
+++ b/tests/pages.test.js
@@ -34,6 +34,9 @@ const keyParameters = d => sections(read(path.join(d.dir, 'README.md')))['Key pa
const ENTRANCE_EXIT = '02-entrance-and-exit';
+// The Pause button of a loop page, exactly as in the template; {MODE} is '' (the page pauses itself) or '="css"'.
+const PAUSE = '<button class="hb-play" type="button" id="btn-pause" data-hb-pause{MODE} data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>';
+
test('every Entrance & Exit demo uses the guided-steps page', () => {
const left = demos.filter(d => d.cat === ENTRANCE_EXIT && !steps.includes(d)).map(d => d.slug);
assert.deepEqual(left, []);
@@ -75,12 +78,12 @@ for (const d of steps) {
}
if (kind === 'loop') {
assert.equal(count(html, 'data-hb-pause'), 1, 'one Pause control');
- assert.match(player, /<button class="hb-play" type="button" id="btn-pause" data-hb-pause(?:="css")? data-state="playing">/,
- 'Pause is in the player bar and starts in the playing state');
+ assert.ok(['', '="css"'].some(mode => player.includes(PAUSE.replace('{MODE}', mode))),
+ 'the Pause button is in the player bar exactly as in the template, starting in the playing state');
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']) {
+ for (const marker of ['data-hb-loop', 'data-hb-slowmo', 'data-hb-pause']) {
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.mjs
index 33ae0ea2..6892d454 100644
--- a/tools/check-pages.mjs
+++ b/tools/check-pages.mjs
@@ -210,7 +210,7 @@ async function loopProblems(reduced) {
const problems = [];
if (reduced) {
if (await state() !== 'paused') problems.push('the loop does not start paused under reduced motion');
- else if (await stageChanges(1500)) problems.push('the stage moves while paused under reduced motion');
+ else if (await stageChanges(4000)) problems.push('the stage moves while paused under reduced motion');
await press();
if (!(await stageChanges(4000))) problems.push('Play does not start the loop under reduced motion');
return problems;
@@ -218,11 +218,11 @@ async function loopProblems(reduced) {
if (!(await stageChanges(4000))) return ['the loop is not moving'];
await press();
await sleep(1500);
- if (await stageChanges(1500)) problems.push('Pause does not stop the stage');
+ if (await stageChanges(4000)) problems.push('Pause does not stop the stage');
await press();
if (!(await stageChanges(4000))) problems.push('Play does not start the stage again');
if (await evaluate(`!!document.querySelector('[data-hb-slowmo="css"]')`)) {
- const rates = () => evaluate(`document.querySelector('.hb-page .stage').getAnimations({ subtree: true }).map(a => a.playbackRate)`);
+ const rates = () => evaluate(`new Promise(done => requestAnimationFrame(() => done(document.querySelector('.hb-page .stage').getAnimations({ subtree: true }).map(a => a.playbackRate))))`);
const toggle = () => evaluate(`document.querySelector('[data-hb-slowmo]').click()`);
await toggle();
await sleep(200);