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: the home page's tiles, search, Show all, All animations and address; the check tries them
matin82fdf5585819
diff --git a/index.html b/index.htmlindex a97a8a8b..acba1a0b 100644--- a/index.html+++ b/index.html@@ -1729,13 +1729,132 @@ document.querySelectorAll('[data-count]').forEach(el=>{const n=ALL.filter(e=>e.places.includes(el.dataset.count)).length;el.textContent=n+(n===1?' animation':' animations');});-showCards(PICKS.map(s=>BY_SLUG[s]));+// ---------- Views, search and the address ----------+const PAGE=8;+const STOP=new Set(['a','an','and','the','that','this','to','for','with','when','on','in','of','my','it','i','want','make','some']);+const stem=w=>w.length>3?w.replace(/(ing|ed|es|s)$/,''):w;+function queryWords(text){return [...new Set(wordsOf(text).filter(w=>!STOP.has(w)).map(stem).filter(w=>w.length>=2))];}+// A word counts 3 in the name, 2 in a place name, 1 in the description or category; each is matched by the start of a word.+function score(e,words){+ let s=0;+ for(const w of words){+ if(e.nameW.some(x=>x.startsWith(w)))s+=3;+ if(e.placeW.some(x=>x.startsWith(w)))s+=2;+ if(e.descW.some(x=>x.startsWith(w)))s+=1;+ }+ return s;+}+function search(text){+ const words=queryWords(text);+ if(!words.length)return [];+ return ALL.map(e=>({e,s:score(e,words)})).filter(x=>x.s>0).sort((a,b)=>b.s-a.s||a.e.order-b.e.order).map(x=>x.e);+}+function showGroups(){+ const boxes=[],cards=[];+ CATS.forEach(cat=>{+ const list=ALL.filter(e=>e.cat===cat),box=document.createElement('section');+ box.className='group';box.id='cat-'+slugify(cat.name);box.setAttribute('aria-labelledby',box.id+'-h');+ box.innerHTML=`<h3 class="ghead" id="${box.id}-h"><span class="gnum">${cat.n}</span><span class="gname">${esc(cat.name)}</span><span class="gcount">${list.length} animations</span></h3>`;+ const grid=document.createElement('div');grid.className='grid';+ list.forEach(e=>{grid.appendChild(CARD[e.slug]);cards.push(CARD[e.slug]);});+ box.appendChild(grid);boxes.push(box);+ });+ cardsBox.replaceChildren(...boxes);+ place(cards);+}+const state={q:'',place:'',view:'',all:false};+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';+function render(){+ const filtered=!!(state.q||state.place||state.view);+ let list=null,title,sub,tags=true;+ if(state.q){+ list=search(state.q);title='Results for “'+state.q+'”';+ sub=list.length===1?'1 animation matches.':list.length+' animations match.';+ }else if(state.place){+ list=ALL.filter(e=>e.places.includes(state.place));title=PLACE[state.place].name;sub=list.length+' animations';tags=false;+ }else if(state.view==='all'){+ title='All animations';sub=ALL.length+' animations in '+CATS.length+' groups.';+ }else{+ 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);+ resultsEl.classList.toggle('no-tags',!tags);+ clearBtn.hidden=!filtered;+ if(list)showCards(state.all||!filtered?list:list.slice(0,PAGE));else showGroups();+ const empty=!!list&&!list.length;+ emptyEl.hidden=!empty;+ if(empty)emptyTitle.textContent='Nothing matches “'+state.q+'” yet';+ if(!filtered||empty){moreAction='all';moreLabel.textContent='Browse all '+ALL.length+' animations';moreBox.hidden=false;}+ else if(list&&!state.all&&list.length>PAGE){moreAction='expand';moreLabel.textContent='Show all '+list.length;moreBox.hidden=false;}+ else moreBox.hidden=true;+ document.querySelectorAll('[data-place]').forEach(b=>b.setAttribute('aria-pressed',String(!state.q&&b.dataset.place===state.place)));+ [q,q2].forEach(input=>{if(input!==document.activeElement&&input.value!==state.q)input.value=state.q;});+ qClear.hidden=!q.value;+}+function writeURL(push){+ const p=new URLSearchParams();+ if(state.q)p.set('q',state.q);+ else if(state.place)p.set('place',PLACE[state.place].url);+ else if(state.view)p.set('view','all');+ if(state.all&&(state.q||state.place))p.set('all','1');+ const url=p.toString()?'?'+p:location.pathname;+ history[push?'pushState':'replaceState'](null,'',url);+}+// Reads the view from the address. Returns the category of an old ?cat= link, to scroll to.+function readURL(){+ const p=new URLSearchParams(location.search),found=PLACE_LIST.find(x=>x.url===p.get('place')),cat=p.get('cat')||'';+ Object.assign(state,{q:(p.get('q')||'').trim(),place:'',view:'',all:p.get('all')==='1'});+ if(!state.q&&found)state.place=found.key;+ else if(!state.q&&(p.get('view')==='all'||cat))state.view='all';+ q.value=q2.value=state.q;+ return cat;+}+function go(next,push){Object.assign(state,{q:'',place:'',view:'',all:false},next);writeURL(push);render();}+const toResults=()=>resultsEl.scrollIntoView({behavior:reduce?'auto':'smooth',block:'start'});+document.addEventListener('click',e=>{+ const tile=e.target.closest('[data-place]');+ if(tile){+ const key=tile.dataset.place;+ go(!state.q&&state.place===key?{}:{place:key},true);+ if(phone.matches&&state.place)toResults();+ return;+ }+ const pick=e.target.closest('[data-q]');+ if(pick){go({q:pick.dataset.q},true);if(phone.matches)toResults();}+});+function typed(input){+ (input===q?q2:q).value=input.value;+ Object.assign(state,{q:input.value.trim(),place:'',view:'',all:false});+ writeURL(false);render();+}+q.addEventListener('input',()=>typed(q));+q2.addEventListener('input',()=>typed(q2));+$('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'});});+$('more-btn').addEventListener('click',()=>{+ if(moreAction==='all'){go({view:'all'},true);toResults();}+ else{state.all=true;writeURL(false);render();}+});+$('nav-all').addEventListener('click',e=>{e.preventDefault();go({view:'all'},true);toResults();});+addEventListener('popstate',()=>{readURL();render();});+addEventListener('keydown',e=>{+ const el=document.activeElement,t=el&&el.tagName;+ if(e.key==='/'&&t!=='INPUT'&&t!=='TEXTAREA'){e.preventDefault();q.focus();}+ else if(e.key==='Escape'&&(el===q||el===q2)){el.value='';typed(el);el.blur();}+});+const startCat=readURL();+render();+if(startCat){const g=$('cat-'+startCat);if(g)g.scrollIntoView();}(function(){const btn=$('theme-toggle');if(!btn)return;btn.addEventListener('click',()=>{const next=document.documentElement.dataset.theme==='light'?'dark':'light';document.documentElement.dataset.theme=next;try{localStorage.setItem('ah-theme',next);}catch(e){}});})();-addEventListener('keydown',e=>{const t=document.activeElement&&document.activeElement.tagName;- if(e.key==='/'&&t!=='INPUT'&&t!=='TEXTAREA'){e.preventDefault();$('q').focus();}});</script></body></html>diff --git a/tools/check-pages.mjs b/tools/check-pages.mjsindex c09e638c..4c7a46af 100644--- a/tools/check-pages.mjs+++ b/tools/check-pages.mjs@@ -434,6 +434,64 @@ async function scrollProblems(reduced) {return problems;}+// 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.+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 })); })()`);+ 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 sleep(300);+ v = await view();+ if (v.cards !== 15 || v.more !== '' || v.search !== '?place=buttons&all=1') problems.push(`Show all: ${JSON.stringify(v)}`);+ 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 type('a button that bounces when clicked');+ await sleep(300);+ const found = await evaluate(`[...document.querySelectorAll('#cards .card .title a')].map(a => a.textContent)`);+ if (found[0] !== 'Click / Tap Ripple' || !found.slice(0, 4).includes('Bounce In')) problems.push(`search order: ${found.slice(0, 5).join(', ')}`);+ await type('zebra');+ 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 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)}`);+ // 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;+ const loaded = new Promise(resolve => { onLoad = msg => { if (msg.method === 'Page.loadEventFired') resolve(); }; listeners.add(onLoad); });+ await send('Page.navigate', { url: `${BASE}/${query}` });+ try { await withTimeout(loaded, LOAD_TIMEOUT); } catch { problems.push(`${query} did not load`); }+ listeners.delete(onLoad);+ await sleep(300);+ const got = await evaluate(`({ title: document.getElementById('results-title').textContent,+ top: (() => { const g = document.getElementById('cat-micro-interactions'); return g ? Math.round(g.getBoundingClientRect().top) : null; })() })`);+ if (got.title !== want) problems.push(`${query}: heading "${got.title}"`);+ if (query.startsWith('?cat=') && (got.top === null || Math.abs(got.top - 12) > 24)) problems.push(`${query}: the category heading is at ${got.top}px, not at the top`);+ }+ return problems;+}++// Home page, phone run: a tile press scrolls to the results, and the slim bar sticks to the top with that place pressed.+async function homePhoneProblems() {+ 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)}`];+}+// The end of the run, done once: after the last page, after Ctrl+C and after an error outside the main flow.let cleaning = null;function cleanUp() {@@ -531,7 +589,8 @@ try {if (result.kind === 'scroll' && (setup.moves || setup.reduce)) problems.push(...await scrollProblems(!!setup.reduce));}if (home) {- // Task 5 and Task 6 add the home page's interaction checks here.+ if (setup.moves) problems.push(...await homeViewProblems());+ if (setup.name === 'phone') problems.push(...await homePhoneProblems());}} catch (err) {problems.push(`check failed: ${err.message}`);