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: the home page keeps keyboard focus when a button hides itself, and the phone bar stays while its search box is in use
matina1531bdc0dc8
diff --git a/index.html b/index.htmlindex acba1a0b..9a5d4780 100644--- a/index.html+++ b/index.html@@ -1034,7 +1034,7 @@ button,input{font:inherit;color:inherit}</div></div><div class="rhead">- <div><h2 class="rtitle" id="results-title">Good places to start</h2><p class="rsub" id="results-sub" aria-live="polite">Eight favorites from different places. Pick a place above to see more.</p></div>+ <div><h2 class="rtitle" id="results-title" tabindex="-1">Good places to start</h2><p class="rsub" id="results-sub" aria-live="polite">Eight favorites from different places. Pick a place above to see more.</p></div><button type="button" class="pillbtn" id="clear-view" hidden><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>Clear</button></div><div id="cards"></div>@@ -1763,12 +1763,19 @@ function showGroups(){place(cards);}const state={q:'',place:'',view:'',all:false};+const isFiltered=()=>!!(state.q||state.place||state.view);const q=$('q'),q2=$('q2'),qClear=$('q-clear'),titleEl=$('results-title'),subEl=$('results-sub'),clearBtn=$('clear-view'),emptyEl=$('empty'),emptyTitle=$('empty-title'),moreBox=$('more'),moreLabel=$('more-label');const phone=matchMedia('(max-width:600px)');let moreAction='all';+const pinbar=$('pinbar');+// The phone bar is there while a view other than Start is open and while its own search box has focus, so emptying the box does not take the box away.+const syncBar=()=>resultsEl.classList.toggle('filtered',isFiltered()||document.activeElement===q2);+// A pressed button that goes away with the view hands keyboard focus to the results heading. No scrolling: the callers that move the page scroll it themselves.+const toTitle=()=>titleEl.focus({preventScroll:true});+const gone=el=>!el.getClientRects().length;function render(){- const filtered=!!(state.q||state.place||state.view);+ const filtered=isFiltered();let list=null,title,sub,tags=true;if(state.q){list=search(state.q);title='Results for “'+state.q+'”';@@ -1781,7 +1788,7 @@ function render(){list=PICKS.map(s=>BY_SLUG[s]);title='Good places to start';sub='Eight favorites from different places. Pick a place above to see more.';}titleEl.textContent=title;subEl.textContent=sub;- resultsEl.classList.toggle('filtered',filtered);+ syncBar();resultsEl.classList.toggle('no-tags',!tags);clearBtn.hidden=!filtered;if(list)showCards(state.all||!filtered?list:list.slice(0,PAGE));else showGroups();@@ -1821,10 +1828,11 @@ document.addEventListener('click',e=>{const key=tile.dataset.place;go(!state.q&&state.place===key?{}:{place:key},true);if(phone.matches&&state.place)toResults();+ if(gone(tile))toTitle();return;}const pick=e.target.closest('[data-q]');- if(pick){go({q:pick.dataset.q},true);if(phone.matches)toResults();}+ if(pick){go({q:pick.dataset.q},true);if(phone.matches)toResults();if(gone(pick))toTitle();}});function typed(input){(input===q?q2:q).value=input.value;@@ -1833,15 +1841,17 @@ function typed(input){}q.addEventListener('input',()=>typed(q));q2.addEventListener('input',()=>typed(q2));+// Moving between the bar's own buttons does not count: a tap on a chip must still find the chip.+pinbar.addEventListener('focusout',e=>{if(!pinbar.contains(e.relatedTarget))syncBar();});$('search-form').addEventListener('submit',e=>{e.preventDefault();toResults();});qClear.addEventListener('click',()=>{q.value='';typed(q);q.focus();});-clearBtn.addEventListener('click',()=>go({},true));-$('pin-back').addEventListener('click',()=>{go({},true);scrollTo({top:0,behavior:reduce?'auto':'smooth'});});+clearBtn.addEventListener('click',()=>{go({},true);toTitle();});+$('pin-back').addEventListener('click',()=>{go({},true);scrollTo({top:0,behavior:reduce?'auto':'smooth'});toTitle();});$('more-btn').addEventListener('click',()=>{- if(moreAction==='all'){go({view:'all'},true);toResults();}- else{state.all=true;writeURL(false);render();}+ if(moreAction==='all'){go({view:'all'},true);toResults();toTitle();}+ else{state.all=true;writeURL(false);render();(cardsBox.querySelectorAll('.card .title a')[PAGE]||titleEl).focus();} // the first new card});-$('nav-all').addEventListener('click',e=>{e.preventDefault();go({view:'all'},true);toResults();});+$('nav-all').addEventListener('click',e=>{e.preventDefault();go({view:'all'},true);toResults();toTitle();});addEventListener('popstate',()=>{readURL();render();});addEventListener('keydown',e=>{const el=document.activeElement,t=el&&el.tagName;diff --git a/tools/check-pages.mjs b/tools/check-pages.mjsindex 4c7a46af..b90b9e51 100644--- a/tools/check-pages.mjs+++ b/tools/check-pages.mjs@@ -436,24 +436,41 @@ async function scrollProblems(reduced) {// Home page, desktop run: a tile press shows that place and changes the address, Show all shows the rest, Back returns to// the start, a plain sentence finds the right animations, a word with no match says so, All animations lists every card-// under its seven headings, and the old ?q= and ?cat= links still work. Leaves the home page on ?cat=micro-interactions.+// under its seven headings, and the old ?q= and ?cat= links still work. Keyboard focus is not dropped or left behind when a+// pressed button hides or the page scrolls away: Show all puts it on the first new card; Clear, a suggestion in the+// Nothing-found panel and Browse all (the button and the link) put it on the results heading. Leaves the home page on+// ?cat=micro-interactions.async function homeViewProblems() {const problems = [];const view = () => evaluate(`({ title: document.getElementById('results-title').textContent, cards: document.querySelectorAll('#cards .card').length,more: document.getElementById('more').hidden ? '' : document.getElementById('more-label').textContent, search: location.search })`);const type = text => evaluate(`(() => { const q = document.getElementById('q'); q.value = ${JSON.stringify(text)}; q.dispatchEvent(new Event('input', { bubbles: true })); })()`);+ // Where keyboard focus is: an id, "card link N" for a card's title link, or the tag name.+ const focused = () => evaluate(`(() => { const a = document.activeElement, links = [...document.querySelectorAll('#cards .card .title a')];+ return a.id || (links.includes(a) ? 'card link ' + (links.indexOf(a) + 1) : a.tagName.toLowerCase()); })()`);+ // A press as the keyboard makes it: the control has focus, then it is activated.+ const press = selector => evaluate(`(() => { const el = document.querySelector(${JSON.stringify(selector)}); el.focus(); el.click(); })()`);await evaluate(`document.querySelector('.place[data-place="btn"]').click()`);await sleep(300);let v = await view();if (v.title !== 'Buttons' || v.cards !== 8 || v.more !== 'Show all 15' || v.search !== '?place=buttons') problems.push(`Buttons tile: ${JSON.stringify(v)}`);- await evaluate(`document.getElementById('more-btn').click()`);+ await press('#more-btn');await sleep(300);v = await view();if (v.cards !== 15 || v.more !== '' || v.search !== '?place=buttons&all=1') problems.push(`Show all: ${JSON.stringify(v)}`);+ let on = await focused();+ if (on !== 'card link 9') problems.push(`Show all: keyboard focus is on ${on}, not on the ninth card's link`);await evaluate(`history.back()`);await sleep(500);v = await view();if (v.title !== 'Good places to start' || v.cards !== 8 || v.search !== '') problems.push(`Back: ${JSON.stringify(v)}`);+ await evaluate(`document.querySelector('.place[data-place="text"]').click()`);+ await sleep(300);+ await press('#clear-view');+ await sleep(300);+ v = await view();+ on = await focused();+ if (v.title !== 'Good places to start' || v.cards !== 8 || on !== 'results-title') problems.push(`Clear: ${JSON.stringify(v)}, keyboard focus is on ${on}`);await type('a button that bounces when clicked');await sleep(300);const found = await evaluate(`[...document.querySelectorAll('#cards .card .title a')].map(a => a.textContent)`);@@ -462,10 +479,24 @@ async function homeViewProblems() {await sleep(300);const empty = await evaluate(`!document.getElementById('empty').hidden && document.getElementById('empty-title').textContent`);if (empty !== 'Nothing matches “zebra” yet') problems.push(`nothing found: ${empty}`);- await evaluate(`document.getElementById('nav-all').click()`);+ await press('#empty [data-q]');+ await sleep(300);+ v = await view();+ on = await focused();+ if (!v.title.startsWith('Results for') || v.cards === 0 || on !== 'results-title') problems.push(`Nothing-found suggestion: ${JSON.stringify(v)}, keyboard focus is on ${on}`);+ await type('zebra');+ await sleep(300);+ await press('#more-btn');+ await sleep(500);+ v = await view();+ on = await focused();+ if (v.title !== 'All animations' || on !== 'results-title') problems.push(`Browse all button: ${JSON.stringify(v)}, keyboard focus is on ${on}`);+ await press('#nav-all');await sleep(500);const all = await evaluate(`({ groups: document.querySelectorAll('#cards .group').length, cards: document.querySelectorAll('#cards .card').length, search: location.search })`);if (all.groups !== 7 || all.cards !== 129 || all.search !== '?view=all') problems.push(`All animations: ${JSON.stringify(all)}`);+ on = await focused();+ if (on !== 'results-title') problems.push(`Browse all link: keyboard focus is on ${on}, not on the results heading`);// Old links keep working: ?q= opens the search, ?cat= opens All animations at that category's heading.for (const [query, want] of [['?q=fade', 'Results for “fade”'], ['?cat=micro-interactions', 'All animations']]) {let onLoad;@@ -483,13 +514,50 @@ async function homeViewProblems() {}// Home page, phone run: a tile press scrolls to the results, and the slim bar sticks to the top with that place pressed.+// Emptying the bar's own search box keeps the bar, and the focus in the box, until the box is left. A chip pressed again and+// the back arrow go away with the bar, so keyboard focus moves to the results heading (the arrow also scrolls to the top).async function homePhoneProblems() {+ const now = () => evaluate(`({ title: document.getElementById('results-title').textContent, focus: document.activeElement.id || document.activeElement.tagName.toLowerCase(),+ shown: getComputedStyle(document.getElementById('pinbar')).display !== 'none', scrolled: Math.round(scrollY) })`);+ const press = selector => evaluate(`(() => { const el = document.querySelector(${JSON.stringify(selector)}); el.focus(); el.click(); })()`);+ const typeInBar = text => evaluate(`(() => { const box = document.getElementById('q2'); box.value = ${JSON.stringify(text)}; box.dispatchEvent(new Event('input', { bubbles: true })); })()`);await evaluate(`document.querySelector('.place[data-place="text"]').click()`);await sleep(900);const v = await evaluate(`(() => { const bar = document.getElementById('pinbar');return { title: document.getElementById('results-title').textContent, shown: getComputedStyle(bar).display !== 'none',top: Math.round(bar.getBoundingClientRect().top), pressed: [...bar.querySelectorAll('[aria-pressed="true"]')].map(b => b.textContent) }; })()`);- return v.title === 'Text' && v.shown && Math.abs(v.top) <= 1 && v.pressed.join() === 'Text' ? [] : [`phone, Text tile: ${JSON.stringify(v)}`];+ const problems = v.title === 'Text' && v.shown && Math.abs(v.top) <= 1 && v.pressed.join() === 'Text' ? [] : [`phone, Text tile: ${JSON.stringify(v)}`];+ // This headless Chrome never has its page in focus, so a script's focus() and blur() send no focus events, and the bar+ // listens for one (leaving its box). The page counts as focused for the rest of this run, as it does for a visitor.+ await send('Emulation.setFocusEmulationEnabled', { enabled: true });+ try {+ await evaluate(`document.getElementById('q2').focus()`);+ await typeInBar('fade');+ await sleep(200);+ await typeInBar('');+ await sleep(200);+ let b = await now();+ if (b.title !== 'Good places to start' || !b.shown || b.focus !== 'q2') problems.push(`phone, search box in the bar emptied: ${JSON.stringify(b)}`);+ await evaluate(`document.getElementById('q2').blur()`);+ await sleep(200);+ b = await now();+ if (b.shown) problems.push(`phone, the bar stays after its emptied search box is left: ${JSON.stringify(b)}`);+ await evaluate(`document.querySelector('.place[data-place="text"]').click()`);+ await sleep(900);+ await press('.pchip[data-place="text"]');+ await sleep(300);+ b = await now();+ if (b.title !== 'Good places to start' || b.shown || b.focus !== 'results-title') problems.push(`phone, pressed chip pressed again: ${JSON.stringify(b)}`);+ await evaluate(`document.querySelector('.place[data-place="text"]').click()`);+ await sleep(900);+ await press('#pin-back');+ await sleep(1300);+ b = await now();+ if (b.title !== 'Good places to start' || b.shown || b.focus !== 'results-title' || b.scrolled > 1) problems.push(`phone, back arrow: ${JSON.stringify(b)}`);+ } finally {+ await send('Emulation.setFocusEmulationEnabled', { enabled: false });+ }+ return problems;}// The end of the run, done once: after the last page, after Ctrl+C and after an error outside the main flow.