כבר ב-3 מדפי הנחיתה שלנו
Orrowby dial
לחצו על קישור בעמוד: המעבר מתנגן, וחזרה · כל שינוי מופיע כאן, בזמן אמת
מעברים · All You Need Is Taste · שלשום
A Transition (mount → destroy) started from a menu.
A nav card (mark, page name, two-line icon) opens on a mouse's entry or a tap on the icon: the lines slide 3 px each into a minus over 400 ms and, from 150 ms, the menu card drops open — clip uncovered from its top edge, faded in, its rows settling from scale 1.1 and blur(10px) — 400 ms, cubic-bezier(.19,1,.22,1); closing is instant. A click on any row, the current page's included, changes page in 800 ms: the page being left scales to 1.1 and fades to 0.5 over a dark ground; the new page opens from the centre (inset(50% round 12px) scale 1.1 → inset(0 round 12px) scale 1 at 90 % → square at 100 %), cubic-bezier(.25,.1,.25,1); the card never moves and cross-fades in 250 ms from open with the old name to closed with the new. Presets: Hobday & Lune, Fennick's, Salle Contre.
זה בשבילך?
מתאים ל
- אתר קטן מרובה עמודים שמנווטים בו מכרטיס תפריט צף אחד
- אתר של סטודיו, מועדון או חנות עם תמונה לכל עמוד
לא מתאים ל
- אתר עם הרבה עמודים: שורת תפריט אחת לכל עמוד
- דפדפנים בלי View Transitions בין מסמכים, שבהם העמודים פשוט מתחלפים
A pale card with hairline frame floating over pale pages; serif page names, a small sans bar, one accent for the current row.
איך זה בנוי
פריסה ומבנה
A screen of 16:10 (3:4 under a 520px root): two pages and the nav card centred at the top.
Nav card
About 30 % of the width (at least 250px): a bar with the mark, the page's name and the icon; 10px below it the menu card, laid out even when closed: a small heading, then one row per page — a 3:2 picture beside a serif name about 2.6 % of the width, the current one in the accent.
Pages
First: a serif title and four 3:4 plates. Second: a wide picture band, a giant serif title, stand-in lines.
רכיבים מיוחדים · 1
Menu card and centre windowThe menu and the move
The menu and the move
Menu open: fill backwards so the from-state holds through the 150 ms delay; menu opacity, frame clip inset(0 0 <height-2>px 0 round r) → inset(0 round r) with opacity, inner opacity + scale(1.1) + blur(10px) → none. Row click: the open card is cloned over itself, the real card closed and renamed, the clone fades 1 → 0 and the card 0 → 1 in 250 ms; the page move as in the centre-window transition. A row for the page shown plays the move onto itself.
הערות
Reduced motion: the menu only fades, the icon does not slide, a row swaps the page at once. Across real pages: cross-document View Transitions with the card named nav-card, and a small script for the menu and for a same-page row (a same-URL navigation gets no transition from the browser, so it is played in the document); the opt-in also inline in each head.
ה-prompt המלא, חלק אחר חלק
Default (Hobday & Lune): pages #E8E4DC / #F4F1EB, ink #12100E, card #F4F1EB, accent #5B2A86, ground #12100E. Fennick's: #E3E5DF / #F4F3EC, ink #14201B, accent #1C4434, ground #0F1A16. Salle Contre: #F2F4F8 / #FBFCFE, ink #13205E, accent #13B15A, ground #0B1130.
מטא
- יוצר
- All You Need Is Taste
- פורסם
- שלשום
עוד בסגנון הזה
שאלות
האם החלפת עמוד מתפריט כרטיס בחינם?
כן. התצוגה החיה, ה-design spec וכל מה שהעמוד הזה מאפשר לקחת — בחינם.
מה מקבלים?
תצוגה חיה שאפשר לפתוח במסך מלא, ה-design spec — פלטה, גופנים, פריסה וכל רכיב, כתוב בשביל סוכן והקוד כחבילה עצמאית להדבקה, עם האפשרויות שלה.
איך משתמשים בזה עם סוכן הקוד שלי?
לחצו על ״העתקה לסוכן שלך״ והדביקו את המשפט ב-Claude Code, ב-Cursor, ב-Codex או ב-Lovable. הסוכן קורא את ה-design spec ובונה אותו בפרויקט שלכם: שומר על איך שזה עובד ומחליף למותג שלכם — שם, טקסטים, צבעים, גופנים ותמונות.
ארבעה קבצים, בלי תלויות. הכול תחת מחלקת שורש אחת; את העיצוב משנים דרך ה-tokens שלה.
element.html
2.7 KB<section class="ayt-menu-card" data-element="menu-opened-transition" aria-label="Two sample pages under a nav card; a row of its menu plays the move to that page">
<div class="ayt-menu-card__screen" data-part="screen">
<article class="ayt-menu-card__page" data-part="page" data-page="from">
<h1 class="ayt-menu-card__title" data-part="title" data-slot="fromTitle">Every public clock in Lammershire, kept.</h1>
<p class="ayt-menu-card__lede"><span class="ayt-menu-card__line"></span><span class="ayt-menu-card__line ayt-menu-card__line--short"></span></p>
<div class="ayt-menu-card__plates" aria-hidden="true">
<span class="ayt-menu-card__plate"></span><span class="ayt-menu-card__plate ayt-menu-card__plate--b"></span><span class="ayt-menu-card__plate ayt-menu-card__plate--c"></span><span class="ayt-menu-card__plate ayt-menu-card__plate--b"></span>
</div>
</article>
<article class="ayt-menu-card__page ayt-menu-card__page--next" data-part="page" data-page="to" hidden>
<span class="ayt-menu-card__hero" aria-hidden="true"></span>
<h1 class="ayt-menu-card__title ayt-menu-card__title--giant" data-part="title" data-slot="toTitle">Orrowby dial</h1>
<p class="ayt-menu-card__lede"><span class="ayt-menu-card__line"></span><span class="ayt-menu-card__line"></span><span class="ayt-menu-card__line ayt-menu-card__line--short"></span></p>
</article>
<header class="ayt-menu-card__card" data-part="card">
<div class="ayt-menu-card__bar">
<span class="ayt-menu-card__mark" data-slot="brand">Hobday & Lune</span>
<span class="ayt-menu-card__label" data-part="label" aria-live="polite">The clocks</span>
<button class="ayt-menu-card__toggle" type="button" data-part="toggle" aria-expanded="false" aria-label="Menu"><span class="ayt-menu-card__icon-line"></span><span class="ayt-menu-card__icon-line"></span></button>
</div>
<nav class="ayt-menu-card__menu" data-part="menu" aria-label="Pages">
<div class="ayt-menu-card__frame" data-part="frame">
<div class="ayt-menu-card__inner" data-part="inner">
<p class="ayt-menu-card__heading" data-slot="heading">Pages</p>
<a class="ayt-menu-card__row" href="#from" data-to="from" aria-current="page"><span class="ayt-menu-card__thumb" aria-hidden="true"></span><span class="ayt-menu-card__name" data-slot="fromName">The clocks</span></a>
<a class="ayt-menu-card__row" href="#to" data-to="to"><span class="ayt-menu-card__thumb ayt-menu-card__thumb--next" aria-hidden="true"></span><span class="ayt-menu-card__name" data-slot="toName">Orrowby dial</span></a>
</div>
</div>
</nav>
</header>
</div>
</section>element.css
7.2 KB/* Menu Card Page Change (ADR-0047). Two sample pages in a screen of their own
under a nav card whose menu changes page; element.js plays the moves.
Every rule under the root. */
.ayt-menu-card {
--ayt-menu-card-ground: #12100e;
--ayt-menu-card-paper: #e8e4dc;
--ayt-menu-card-ink: #12100e;
--ayt-menu-card-paper-next: #f4f1eb;
--ayt-menu-card-card: #f4f1eb;
--ayt-menu-card-accent: #5b2a86;
--ayt-menu-card-icon-ms: 400ms;
--ayt-menu-card-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
--ayt-menu-card-text: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
container-type: inline-size;
display: block;
inline-size: 100%;
}
.ayt-menu-card__screen {
position: relative;
overflow: hidden;
aspect-ratio: 16 / 10;
background: var(--ayt-menu-card-ground);
isolation: isolate;
color: var(--ayt-menu-card-ink);
font-family: var(--ayt-menu-card-text);
}
.ayt-menu-card__page {
position: absolute;
inset: 0;
z-index: 2;
overflow: hidden auto;
box-sizing: border-box;
display: flex;
flex-direction: column;
padding: 10cqi 5cqi 4cqi;
background: var(--ayt-menu-card-paper);
transform-origin: 50% 50%;
scrollbar-width: none;
}
.ayt-menu-card__page[hidden] { display: none; }
.ayt-menu-card__page--next { background: var(--ayt-menu-card-paper-next); }
.ayt-menu-card__title {
margin: 0;
max-inline-size: 16ch;
font-family: var(--ayt-menu-card-display);
font-weight: 500;
font-size: 6.2cqi;
line-height: 0.98;
letter-spacing: -0.02em;
text-wrap: balance;
}
.ayt-menu-card__title:focus { outline: none; }
.ayt-menu-card__title--giant { margin-block-start: 3cqi; font-size: 10.5cqi; max-inline-size: none; }
.ayt-menu-card__lede { display: grid; gap: 0.9cqi; margin: 2.4cqi 0 0; inline-size: 34cqi; }
.ayt-menu-card__line {
display: block;
block-size: max(4px, 0.5cqi);
border-radius: 99px;
background: currentColor;
opacity: 0.22;
}
.ayt-menu-card__line--short { inline-size: 60%; }
.ayt-menu-card__plates { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.4cqi; margin-block-start: auto; padding-block-start: 3cqi; }
.ayt-menu-card__plate,
.ayt-menu-card__hero,
.ayt-menu-card__thumb {
display: block;
border-radius: 0.8cqi;
background:
radial-gradient(80% 70% at 30% 25%, color-mix(in srgb, var(--ayt-menu-card-paper-next) 45%, transparent), transparent 65%),
linear-gradient(150deg, color-mix(in srgb, var(--ayt-menu-card-accent) 70%, var(--ayt-menu-card-paper)), color-mix(in srgb, var(--ayt-menu-card-ink) 70%, var(--ayt-menu-card-accent)));
}
.ayt-menu-card__plate { aspect-ratio: 3 / 4; }
.ayt-menu-card__plate--b { filter: saturate(0.6) brightness(1.15); }
.ayt-menu-card__plate--c { filter: hue-rotate(40deg) saturate(0.7); }
.ayt-menu-card__hero { block-size: 17cqi; border-radius: 1cqi; filter: hue-rotate(40deg) saturate(0.7); }
/* The nav card: a bar, and the menu below it, laid out even when closed so
the card is one size in both pictures of the page change. */
.ayt-menu-card__card {
position: absolute;
z-index: 4;
inset-block-start: 2.2cqi;
inset-inline-start: 50%;
inline-size: min(30cqi, calc(100% - 24px));
min-inline-size: 250px;
translate: -50% 0;
font-size: max(12px, 1.15cqi);
}
.ayt-menu-card__bar {
display: flex;
align-items: center;
gap: 1.4cqi;
block-size: max(42px, 4.2cqi);
box-sizing: border-box;
padding-inline: 1.6cqi 0.6cqi;
border-radius: 0.9cqi;
background: var(--ayt-menu-card-card);
box-shadow: 0 0 0 1px color-mix(in srgb, var(--ayt-menu-card-ink) 15%, transparent);
}
.ayt-menu-card__mark { font-weight: 700; letter-spacing: 0.03em; white-space: nowrap; }
.ayt-menu-card__label { margin-inline-start: auto; opacity: 0.65; white-space: nowrap; }
.ayt-menu-card__toggle {
position: relative;
inline-size: max(34px, 3.2cqi);
block-size: max(34px, 3.2cqi);
border: 0;
border-radius: 0.6cqi;
background: transparent;
color: inherit;
cursor: pointer;
}
.ayt-menu-card__toggle:focus-visible { outline: 2px solid var(--ayt-menu-card-accent); outline-offset: 1px; }
.ayt-menu-card__icon-line {
position: absolute;
inset-inline-start: 28%;
inset-inline-end: 28%;
block-size: 1.5px;
background: currentColor;
transition: translate var(--ayt-menu-card-icon-ms) cubic-bezier(0.19, 1, 0.22, 1);
}
.ayt-menu-card__icon-line:first-child { inset-block-start: calc(50% - 3.75px); }
.ayt-menu-card__icon-line:last-child { inset-block-start: calc(50% + 2.25px); }
.ayt-menu-card__card--open .ayt-menu-card__icon-line:first-child { translate: 0 3px; }
.ayt-menu-card__card--open .ayt-menu-card__icon-line:last-child { translate: 0 -3px; }
.ayt-menu-card__menu { padding-block-start: 10px; visibility: hidden; opacity: 0; }
.ayt-menu-card__card--open .ayt-menu-card__menu { visibility: visible; opacity: 1; }
.ayt-menu-card__frame {
overflow: hidden;
border-radius: 0.9cqi;
background: var(--ayt-menu-card-card);
box-shadow: 0 0 0 1px color-mix(in srgb, var(--ayt-menu-card-ink) 15%, transparent);
}
.ayt-menu-card__inner { display: grid; gap: 1.1cqi; padding: 1.6cqi 2cqi 2cqi; transform-origin: 50% 0; }
.ayt-menu-card__heading { margin: 0; font-size: max(10px, 0.95cqi); letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.55; }
.ayt-menu-card__row { display: grid; grid-template-columns: max(58px, 6cqi) 1fr; align-items: center; gap: 1.4cqi; color: inherit; text-decoration: none; }
.ayt-menu-card__thumb { aspect-ratio: 3 / 2; border-radius: 0.5cqi; }
.ayt-menu-card__thumb--next { filter: hue-rotate(40deg) saturate(0.7); }
.ayt-menu-card__name { font-family: var(--ayt-menu-card-display); font-size: max(20px, 2.6cqi); line-height: 1; letter-spacing: -0.01em; transition: color 0.2s ease; }
.ayt-menu-card__row[aria-current="page"] .ayt-menu-card__name,
.ayt-menu-card__row:hover .ayt-menu-card__name,
.ayt-menu-card__row:focus-visible .ayt-menu-card__name { color: var(--ayt-menu-card-accent); }
.ayt-menu-card__row:focus-visible { outline: 2px solid var(--ayt-menu-card-accent); outline-offset: 3px; border-radius: 4px; }
/* The open card as it was, over the closing one, for the cross-fade. */
.ayt-menu-card__card--ghost { z-index: 5; pointer-events: none; }
/* The frozen copy of the page being left (element.js puts it here). */
.ayt-menu-card__layer { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
.ayt-menu-card__icon-line { transition: none; }
}
@container (max-width: 520px) {
.ayt-menu-card__screen { aspect-ratio: 3 / 4; }
.ayt-menu-card__page { padding: 22cqi 5cqi 5cqi; }
.ayt-menu-card__title { font-size: 10cqi; }
.ayt-menu-card__title--giant { font-size: 15cqi; margin-block-start: 5cqi; }
.ayt-menu-card__lede { inline-size: 70%; gap: 2cqi; margin-block-start: 5cqi; }
.ayt-menu-card__plates { grid-template-columns: repeat(2, 1fr); gap: 3cqi; }
.ayt-menu-card__plate:nth-child(n + 3) { display: none; }
.ayt-menu-card__hero { block-size: 40cqi; }
.ayt-menu-card__card { inset-block-start: 4cqi; min-inline-size: 0; inline-size: calc(100% - 24px); }
.ayt-menu-card__bar { padding-inline: 4cqi 1cqi; border-radius: 2.4cqi; }
.ayt-menu-card__frame { border-radius: 2.4cqi; }
.ayt-menu-card__inner { gap: 3cqi; padding: 4cqi 5cqi 5cqi; }
.ayt-menu-card__row { gap: 4cqi; }
}element.js
11.5 KB/*
* Menu Card Page Change — a Transition (ADR-0047): one move between two pages,
* started from a menu.
*
* A small nav card floats at the top: a mark, the page's name and a two-line
* icon. The pointer on the card (or a tap on the icon) opens it: the lines
* meet into a minus and, 150 ms later, a menu card drops open below, uncovered
* from its top edge while its rows settle from 1.1 and a 10 px blur — 400 ms on
* an expo-out curve. A row is a small picture beside a large page name. A
* click on any row, the current page's included, changes page in one 800 ms
* movement: the page being left grows to 1.1 and dims to half over a dark
* ground while the new page opens out of the centre in a rounded window, full
* at 90 %, corners square at the end. The card never moves: in 250 ms the open
* menu cross-fades to the closed card carrying the new page's name.
*
* Here the two pages are inside the root's own box (the `screen`); the same
* move between two real documents is the manifest's `acrossPages`. Every
* number below is a default equal to the recorded one. No dependency; the Web
* Animations API only.
*
* mount(root, options) → destroy; destroy.update(options) re-tunes a live
* mount, destroy.go('from' | 'to') plays the move from script, destroy.open()
* and destroy.close() work the menu.
*/
const DEFAULTS = {
pace: 1, // multiplies every duration: 1 is as recorded (move 800 ms, menu 150 + 400 ms, card 250 ms)
swell: 1.1, // the page being left grows to this, and the new page settles from it
dim: 0.5, // the page being left's opacity at the end
radius: 12, // px, the opening window's corners until 90 %
hover: true, // open the menu when a mouse comes onto the card (a tap on the icon always does)
ground: '#12100e', // what the dimmed page shows through to
paper: '#e8e4dc', // the first page's ground
ink: '#12100e', // the words, both pages and the card
paperNext: '#f4f1eb', // the second page's ground
card: '#f4f1eb', // the nav card
accent: '#5b2a86', // the current page's row, and a name under the pointer
brand: null, // words: null keeps the markup's
heading: null,
fromName: null,
fromTitle: null,
toName: null,
toTitle: null,
};
// The shape of the moves, as recorded: not options, so the curves stay the curves.
const MOVE_MS = 800;
const OPEN_AT = 0.9;
const CARD_MS = 250;
const MENU_MS = 400;
const MENU_DELAY_MS = 150;
const MENU_EASE = 'cubic-bezier(0.19, 1, 0.22, 1)';
const MENU_SCALE = 1.1;
const MENU_BLUR = 10;
const EASE = 'cubic-bezier(0.25, 0.1, 0.25, 1)';
const TOKENS = { ground: 'ground', paper: 'paper', ink: 'ink', paperNext: 'paper-next', card: 'card', accent: 'accent' };
const WORDS = ['brand', 'heading', 'fromName', 'fromTitle', 'toName', 'toTitle'];
// The move's end: its animation's `finished`, or the clock when that is late
// (a page that pins its animations, as a frame-by-frame recorder does).
const settled = (animation, ms) =>
Promise.race([animation.finished.catch(() => {}), new Promise((resolve) => setTimeout(resolve, ms + 120))]);
export function mount(root, options = {}) {
let o = { ...DEFAULTS, ...options };
const part = (name) => root.querySelector(`[data-part="${name}"]`);
const screen = part('screen');
const card = part('card');
const label = part('label');
const toggle = part('toggle');
const menu = part('menu');
const frame = part('frame');
const inner = part('inner');
const pages = [...root.querySelectorAll('[data-part="page"]')];
const rows = [...root.querySelectorAll('.ayt-menu-card__row')];
const page = (name) => pages.find((p) => p.dataset.page === name);
const first = pages.find((p) => !p.hidden) ?? pages[0];
let here = first.dataset.page;
const layer = document.createElement('div');
layer.className = 'ayt-menu-card__layer';
layer.setAttribute('aria-hidden', 'true');
screen.prepend(layer);
const saved = new Map();
for (const name of WORDS) root.querySelectorAll(`[data-slot="${name}"]`).forEach((el) => saved.set(el, el.textContent));
const labelText = label.textContent;
const pace = () => Math.max(0.1, Number(o.pace) || 1);
const calm = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
const off = [];
const on = (target, type, fn, opts) => {
target.addEventListener(type, fn, opts);
off.push(() => target.removeEventListener(type, fn, opts));
};
function paint() {
for (const [key, token] of Object.entries(TOKENS)) {
if (typeof o[key] === 'string' && o[key]) root.style.setProperty(`--ayt-menu-card-${token}`, o[key]);
}
root.style.setProperty('--ayt-menu-card-icon-ms', `${MENU_MS * pace()}ms`);
for (const name of WORDS) {
if (typeof o[name] !== 'string' || !o[name]) continue;
root.querySelectorAll(`[data-slot="${name}"]`).forEach((el) => (el.textContent = o[name]));
}
if (!run) label.textContent = nameOf(here);
}
const rowOf = (name) => rows.find((r) => r.dataset.to === name);
const nameOf = (name) => rowOf(name)?.querySelector('.ayt-menu-card__name')?.textContent.trim() ?? name;
// ── The menu: opens over 150 + 400 ms, closes at once ─────────────────────
let isOpen = false;
let menuAnims = [];
const stopMenu = () => {
menuAnims.forEach((a) => a.cancel());
menuAnims = [];
};
function open() {
if (isOpen) return;
isOpen = true;
card.classList.add('ayt-menu-card__card--open');
toggle.setAttribute('aria-expanded', 'true');
menu.inert = false;
stopMenu();
const t = { duration: MENU_MS * pace(), delay: MENU_DELAY_MS * pace(), easing: MENU_EASE, fill: 'backwards' };
if (calm()) {
menuAnims = [menu.animate([{ opacity: 0 }, { opacity: 1 }], t)];
return;
}
// Laid out at full height from the first frame, uncovered from its top edge down.
const rest = Math.max(0, frame.getBoundingClientRect().height - 2);
const r = `round ${parseFloat(getComputedStyle(frame).borderBottomLeftRadius) || 0}px`;
menuAnims = [
menu.animate([{ opacity: 0 }, { opacity: 1 }], t),
frame.animate([{ opacity: 0, clipPath: `inset(0 0 ${rest}px 0 ${r})` }, { opacity: 1, clipPath: `inset(0 0 0px 0 ${r})` }], t),
inner.animate(
[
{ opacity: 0, transform: `scale(${MENU_SCALE})`, filter: `blur(${MENU_BLUR}px)` },
{ opacity: 1, transform: 'scale(1)', filter: 'blur(0px)' },
],
t,
),
];
}
function close() {
if (!isOpen) return;
isOpen = false;
card.classList.remove('ayt-menu-card__card--open');
toggle.setAttribute('aria-expanded', 'false');
menu.inert = true;
stopMenu();
}
menu.inert = true;
const mouse = (event) => o.hover !== false && event.pointerType === 'mouse' && matchMedia('(pointer: fine)').matches;
on(card, 'pointerenter', (event) => mouse(event) && !run && open());
on(card, 'pointerleave', (event) => mouse(event) && !run && close());
on(toggle, 'click', () => (isOpen ? close() : open()));
on(document, 'keydown', (event) => {
if (event.key === 'Escape' && isOpen) {
close();
toggle.focus();
}
});
on(document, 'pointerdown', (event) => isOpen && !card.contains(event.target) && close());
// ── The page movement ──────────────────────────────────────────────────────
let run = null;
function show(name) {
for (const p of pages) {
p.hidden = p.dataset.page !== name;
p.inert = p.hidden;
}
here = name;
for (const r of rows) {
if (r.dataset.to === name) r.setAttribute('aria-current', 'page');
else r.removeAttribute('aria-current');
}
}
function settle(to) {
const title = to.querySelector('[data-part="title"]');
if (title) {
if (!title.hasAttribute('tabindex')) title.setAttribute('tabindex', '-1');
title.focus({ preventScroll: true });
}
root.dispatchEvent(new CustomEvent('transition:end', { detail: { page: here } }));
}
// Every row plays it, the current page's included: that page opens again out of itself.
async function go(name) {
const to = page(name);
if (run || !to) return false;
const from = page(here);
root.dispatchEvent(new CustomEvent('transition:start', { detail: { from: here, to: name } }));
if (calm()) {
close();
show(name);
to.scrollTop = 0;
label.textContent = nameOf(name);
settle(to);
return true;
}
const p = pace();
const mine = (run = { anims: [] });
// The card as it is now (menu open, old name), laid over itself to fade out.
const ghost = card.cloneNode(true);
ghost.removeAttribute('data-part');
ghost.querySelectorAll('[data-part]').forEach((el) => el.removeAttribute('data-part'));
ghost.querySelectorAll('[aria-live]').forEach((el) => el.removeAttribute('aria-live'));
ghost.classList.add('ayt-menu-card__card--ghost');
ghost.inert = true;
ghost.setAttribute('aria-hidden', 'true');
// The page being left, frozen as it is.
const copy = from.cloneNode(true);
copy.removeAttribute('data-part');
copy.inert = true;
layer.append(copy);
copy.scrollTop = from.scrollTop;
close();
card.after(ghost);
label.textContent = nameOf(name);
show(name);
to.scrollTop = 0;
root.setAttribute('data-moving', '');
const r = `${Number(o.radius) || 0}px`;
const fade = { duration: CARD_MS * p, easing: 'ease', fill: 'both' };
const arrive = to.animate(
[
{ offset: 0, clipPath: `inset(50% round ${r})`, transform: `scale(${o.swell})`, easing: EASE },
{ offset: OPEN_AT, clipPath: `inset(0% round ${r})`, transform: 'scale(1)', easing: EASE },
{ offset: 1, clipPath: 'inset(0% round 0px)', transform: 'scale(1)' },
],
{ duration: MOVE_MS * p, fill: 'forwards' },
);
mine.anims = [
copy.animate([{ opacity: 1, transform: 'scale(1)' }, { opacity: o.dim, transform: `scale(${o.swell})` }], {
duration: MOVE_MS * p,
easing: EASE,
fill: 'forwards',
}),
arrive,
ghost.animate([{ opacity: 1 }, { opacity: 0 }], fade),
card.animate([{ opacity: 0 }, { opacity: 1 }], fade),
];
await settled(arrive, MOVE_MS * p);
if (run !== mine) return false;
finish();
settle(to);
return true;
}
function finish() {
if (!run) return;
run.anims.forEach((a) => a.cancel());
run = null;
layer.replaceChildren();
root.querySelectorAll('.ayt-menu-card__card--ghost').forEach((el) => el.remove());
root.removeAttribute('data-moving');
}
on(root, 'click', (event) => {
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
const row = event.target.closest?.('[data-to]');
if (!row || !root.contains(row)) return;
event.preventDefault();
go(row.dataset.to);
});
show(here);
paint();
function destroy() {
off.splice(0).forEach((undo) => undo());
finish();
stopMenu();
close();
layer.remove();
menu.inert = false;
for (const p of pages) {
p.hidden = p !== first;
p.inert = false;
}
for (const [el, text] of saved) el.textContent = text;
label.textContent = labelText;
for (const token of Object.values(TOKENS)) root.style.removeProperty(`--ayt-menu-card-${token}`);
root.style.removeProperty('--ayt-menu-card-icon-ms');
}
destroy.update = (next = {}) => {
o = { ...o, ...next };
paint();
};
destroy.go = go;
destroy.open = open;
destroy.close = close;
return destroy;
}manifest.json
16.1 KB{
"slug": "menu-opened-transition",
"name": "Menu Card Page Change",
"role": "transition",
"summary": "A move between pages started from a menu: a small nav card opens on the pointer (or a tap on its icon) — the icon's lines meet into a minus and, 150 ms later, a menu card drops open, uncovered from its top edge while its rows settle from 1.1 and a 10 px blur, 400 ms. A click on any row, the current page's included, changes page in 800 ms: the page being left grows to 1.1 and dims to half while the new one opens out of the centre in a rounded window; the card never moves and cross-fades in 250 ms to closed, carrying the new name. Two sample pages inside the root to try it; between real pages it is `acrossPages`, cross-document View Transitions with a small script for the menu. Worn by three of our landings: the keepers of a county's public clocks, a flower butcher's and a fencing club.",
"mechanic": "dom",
"interaction": [
"pointer",
"click",
"keyboard"
],
"tokens": {
"--ayt-menu-card-ground": {
"default": "#12100e",
"description": "What the dimmed page shows through to (`ground`)."
},
"--ayt-menu-card-paper": {
"default": "#e8e4dc",
"description": "The first page's ground (`paper`)."
},
"--ayt-menu-card-ink": {
"default": "#12100e",
"description": "The words on both pages and on the card (`ink`)."
},
"--ayt-menu-card-paper-next": {
"default": "#f4f1eb",
"description": "The second page's ground (`paperNext`)."
},
"--ayt-menu-card-card": {
"default": "#f4f1eb",
"description": "The nav card and its menu (`card`)."
},
"--ayt-menu-card-accent": {
"default": "#5b2a86",
"description": "The current page's row and a name under the pointer (`accent`)."
},
"--ayt-menu-card-icon-ms": {
"default": "400ms",
"description": "The icon's lines meeting and parting; written by element.js from `pace`."
},
"--ayt-menu-card-display": {
"default": "\"Iowan Old Style\", \"Palatino Linotype\", Palatino, Georgia, serif",
"description": "Titles and the menu's page names."
},
"--ayt-menu-card-text": {
"default": "ui-sans-serif, system-ui, sans-serif",
"description": "Everything else."
}
},
"slots": {
"brand": {
"selector": "[data-slot=brand]",
"description": "The mark on the card."
},
"heading": {
"selector": "[data-slot=heading]",
"description": "The word over the menu's rows."
},
"fromName": {
"selector": "[data-slot=fromName]",
"description": "The first page's name: its row, and the card's label there."
},
"fromTitle": {
"selector": "[data-slot=fromTitle]",
"description": "The first page's title."
},
"toName": {
"selector": "[data-slot=toName]",
"description": "The second page's name: its row, and the card's label there."
},
"toTitle": {
"selector": "[data-slot=toTitle]",
"description": "The second page's giant title."
}
},
"options": {
"pace": {
"type": "number",
"default": 1,
"description": "Multiplies every duration: 1 is as recorded (the page change 800 ms, the menu 150 + 400 ms, the card's cross-fade 250 ms), 2 is twice as slow."
},
"swell": {
"type": "number",
"default": 1.1,
"description": "How far the page being left grows, and how large the new page starts before settling to 1 (recorded 1.1)."
},
"dim": {
"type": "number",
"default": 0.5,
"description": "The page being left's opacity at the end (recorded 0.5)."
},
"radius": {
"type": "number",
"default": 12,
"description": "The opening window's corners in px until 90 % (recorded 12); square at the end."
},
"hover": {
"type": "boolean",
"default": true,
"description": "Open the menu when a mouse comes onto the card; off, only the icon opens it (a tap always does)."
},
"ground": {
"type": "string",
"default": "#12100e",
"description": "What the dimmed page shows through to."
},
"paper": {
"type": "string",
"default": "#e8e4dc",
"description": "The first page's ground."
},
"ink": {
"type": "string",
"default": "#12100e",
"description": "The words, both pages and the card."
},
"paperNext": {
"type": "string",
"default": "#f4f1eb",
"description": "The second page's ground."
},
"card": {
"type": "string",
"default": "#f4f1eb",
"description": "The nav card and its menu."
},
"accent": {
"type": "string",
"default": "#5b2a86",
"description": "The current page's row, and a name under the pointer."
},
"brand": {
"type": "string",
"default": null,
"description": "The mark on the card; null keeps the markup's."
},
"heading": {
"type": "string",
"default": null,
"description": "The word over the rows."
},
"fromName": {
"type": "string",
"default": null,
"description": "The first page's name."
},
"fromTitle": {
"type": "string",
"default": null,
"description": "The first page's title."
},
"toName": {
"type": "string",
"default": null,
"description": "The second page's name."
},
"toTitle": {
"type": "string",
"default": null,
"description": "The second page's title."
}
},
"presets": {
"hobday-lune-pages": {
"landing": "hobday-lune-public-clock-keepers-landing",
"title": "Hobday & Lune — The clocks to Orrowby dial",
"brand": "Hobday & Lune",
"heading": "Pages",
"fromName": "The clocks",
"fromTitle": "Every public clock in Lammershire, kept.",
"toName": "Orrowby dial",
"toTitle": "Orrowby dial",
"ground": "#12100e",
"paper": "#e8e4dc",
"ink": "#12100e",
"paperNext": "#f4f1eb",
"card": "#f4f1eb",
"accent": "#5b2a86"
},
"fennicks-board": {
"landing": "fennicks-flower-butchers-landing",
"title": "Fennick’s — The shop to Tuesdays",
"brand": "Fennick’s",
"heading": "On the board",
"fromName": "The shop",
"fromTitle": "Cut on Tuesday. Hung by five.",
"toName": "Tuesdays",
"toTitle": "Tuesdays",
"ground": "#0f1a16",
"paper": "#e3e5df",
"ink": "#14201b",
"paperNext": "#f4f3ec",
"card": "#f4f3ec",
"accent": "#1c4434"
},
"salle-contre-pages": {
"landing": "salle-contre-fencing-club-landing",
"title": "Salle Contre — The salle to First lesson",
"brand": "Salle Contre",
"heading": "Pages",
"fromName": "The salle",
"fromTitle": "Put the mask on. We’ll teach the rest.",
"toName": "First lesson",
"toTitle": "First lesson",
"ground": "#0b1130",
"paper": "#f2f4f8",
"ink": "#13205e",
"paperNext": "#fbfcfe",
"card": "#fbfcfe",
"accent": "#13b15a"
}
},
"controls": [
{
"option": "pace",
"type": "range",
"min": 0.5,
"max": 2.5,
"step": 0.05
},
{
"option": "swell",
"type": "range",
"min": 1,
"max": 1.3,
"step": 0.01
},
{
"option": "dim",
"type": "range",
"min": 0,
"max": 1,
"step": 0.05
},
{
"option": "radius",
"type": "range",
"min": 0,
"max": 40,
"step": 1
},
{
"option": "ground",
"type": "color"
},
{
"option": "card",
"type": "color"
},
{
"option": "paperNext",
"type": "color"
},
{
"option": "accent",
"type": "color"
},
{
"option": "hover",
"type": "toggle"
}
],
"size": {
"minHeight": "225px",
"fullBleed": true,
"aspect": "16 / 10"
},
"viewports": [
"desktop",
"mobile"
],
"ground": "#12100e",
"reducedMotion": "The menu only fades in (same delay, length and curve; no uncovering, scale or blur) and the icon changes without sliding; a row shows its page at once with the card closed on the new name, focus on its title. Across pages the opt-in sits inside `prefers-reduced-motion: no-preference`, so the browser simply loads the next page.",
"a11y": "The icon is a real button with aria-expanded and aria-label; the menu is a nav of real links, inert while closed, the current page's row marked aria-current=\"page\"; Escape closes it and returns focus to the icon, a tap outside closes it. The card's label is a polite live region. After the move focus goes to the new page's title (tabindex -1, no scroll); the frozen copy and the fading card are aria-hidden and inert.",
"pairsWith": [
"editorial",
"multi-page",
"navigation",
"small-business"
],
"mood": [
"cinematic",
"calm",
"precise"
],
"source": "hobday-lune-public-clock-keepers-landing",
"update": "mount() returns destroy; destroy.update({ …any option }) re-tunes a live mount (colours and words at once, timings on the next move); destroy.go('from' | 'to') plays the move from script, destroy.open() and destroy.close() work the menu. Events on the root: `transition:start` { from, to }, `transition:end` { page }.",
"acrossPages": {
"summary": "Between real documents the page change is a cross-document View Transition (Chrome and Edge 126+, Safari 18.2+) and the menu a few lines of script: every page loads the stylesheet and the script below and carries the same card. The browser snapshots the page being left with its menu still open, these rules play the two snapshots with the recorded numbers, and the card — named `nav-card` — is lifted out of both and only cross-fades from open to closed. A row for the page already shown would get no transition from the browser (a same-URL navigation), so the script plays that one inside the document. A browser without cross-document View Transitions simply loads the next page, and so does one asking for reduced motion.",
"html": "<!-- In the <head> of every page; the inline opt-in is the surer place\n (with the opt-in only in a linked stylesheet Chrome sometimes skips it). -->\n<link rel=\"stylesheet\" href=\"menu-card.css\">\n<style>@media (prefers-reduced-motion: no-preference) { @view-transition { navigation: auto; } }</style>\n<script type=\"module\" src=\"menu-card.js\"></script>\n\n<!-- The card, the same on every page, the current row marked: -->\n<header class=\"nav-card\">\n <div class=\"nav-card__bar\">\n <a href=\"/\">Hobday & Lune</a>\n <span class=\"nav-card__label\">The clocks</span>\n <button class=\"nav-card__toggle\" type=\"button\" aria-expanded=\"false\" aria-label=\"Menu\">\n <span class=\"nav-card__lines\"><span></span><span></span></span>\n </button>\n </div>\n <nav class=\"nav-card__menu\" aria-label=\"Pages\">\n <div class=\"nav-card__frame\">\n <div class=\"nav-card__inner\">\n <a class=\"nav-card__row\" href=\"/clocks/\" aria-current=\"page\"><img src=\"clocks.jpg\" alt=\"\"> The clocks</a>\n <a class=\"nav-card__row\" href=\"/orrowby/\"><img src=\"orrowby.jpg\" alt=\"\"> Orrowby dial</a>\n </div>\n </div>\n </nav>\n</header>",
"css": "/* Menu Card Page Change between real pages: cross-document View\n Transitions. Every page loads this file and the script below. */\n@media (prefers-reduced-motion: no-preference) {\n @view-transition { navigation: auto; }\n}\n:root { --menu-card-ground: #12100e; }\n\n::view-transition-image-pair(root) { background: var(--menu-card-ground); }\n\n/* The page being left grows to 1.1 and dims to half, 800 ms. */\n::view-transition-old(root) {\n mix-blend-mode: normal;\n transform-origin: 50% 50%;\n animation: menu-card-leave 800ms cubic-bezier(0.25, 0.1, 0.25, 1) both;\n}\n/* The new page opens out of the centre, full at 90 %, corners square last. */\n::view-transition-new(root) {\n mix-blend-mode: normal;\n z-index: 1;\n transform-origin: 50% 50%;\n animation: menu-card-arrive 800ms linear both;\n}\n@keyframes menu-card-leave { to { opacity: 0.5; scale: 1.1; } }\n@keyframes menu-card-arrive {\n 0% { clip-path: inset(50% round 12px); scale: 1.1; animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1); }\n 90% { clip-path: inset(0 round 12px); scale: 1; animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1); }\n 100% { clip-path: inset(0 round 0); scale: 1; }\n}\n\n/* The nav card is lifted out of both pages and stays put: the open menu\n (old page) cross-fades to the closed card (new page) in 250 ms. */\n.nav-card { view-transition-name: nav-card; }\n::view-transition-group(nav-card) { animation-duration: 250ms; }\n::view-transition-old(nav-card),\n::view-transition-new(nav-card) { animation-duration: 250ms; animation-timing-function: ease; }\n\n/* The menu itself: laid out even when closed, so the card is one size in\n both pictures; shown while the card carries .is-open. */\n.nav-card__menu { padding-top: 10px; visibility: hidden; opacity: 0; }\n.nav-card.is-open .nav-card__menu { visibility: visible; opacity: 1; }\n.nav-card__lines span { display: block; height: 1.5px; margin: 4.5px 0; background: currentColor; transition: translate 400ms cubic-bezier(0.19, 1, 0.22, 1); }\n.nav-card.is-open .nav-card__lines span:first-child { translate: 0 3px; }\n.nav-card.is-open .nav-card__lines span:last-child { translate: 0 -3px; }\n\n@media (prefers-reduced-motion: reduce) {\n .nav-card { view-transition-name: none; }\n .nav-card__lines span { transition: none; }\n}\n",
"js": "// The nav card's menu on a real page: the pointer or the icon opens it\n// (150 ms, then 400 ms on an expo-out curve), it closes at once; a row for the\n// page already shown plays the move onto itself, inside the document.\nconst card = document.querySelector('.nav-card');\nconst toggle = card.querySelector('.nav-card__toggle');\nconst frame = card.querySelector('.nav-card__frame');\nconst inner = card.querySelector('.nav-card__inner');\nconst calm = () => matchMedia('(prefers-reduced-motion: reduce)').matches;\nlet anims = [];\n\nfunction open() {\n if (card.classList.contains('is-open')) return;\n card.classList.add('is-open');\n toggle.setAttribute('aria-expanded', 'true');\n const t = { duration: 400, delay: 150, easing: 'cubic-bezier(0.19, 1, 0.22, 1)', fill: 'backwards' };\n if (calm()) { anims = [frame.animate([{ opacity: 0 }, { opacity: 1 }], t)]; return; }\n const rest = frame.getBoundingClientRect().height - 2;\n const r = getComputedStyle(frame).borderBottomLeftRadius;\n anims = [\n frame.animate([{ opacity: 0, clipPath: `inset(0 0 ${rest}px 0 round ${r})` }, { opacity: 1, clipPath: `inset(0 0 0 0 round ${r})` }], t),\n inner.animate([{ opacity: 0, transform: 'scale(1.1)', filter: 'blur(10px)' }, { opacity: 1, transform: 'scale(1)', filter: 'blur(0)' }], t),\n ];\n}\nfunction close() {\n card.classList.remove('is-open');\n toggle.setAttribute('aria-expanded', 'false');\n anims.forEach((a) => a.cancel());\n}\nconst mouse = (e) => e.pointerType === 'mouse' && matchMedia('(pointer: fine)').matches;\nlet moving = false;\ncard.addEventListener('pointerenter', (e) => mouse(e) && !moving && open());\ncard.addEventListener('pointerleave', (e) => mouse(e) && !moving && close());\ntoggle.addEventListener('click', () => (card.classList.contains('is-open') ? close() : open()));\naddEventListener('keydown', (e) => e.key === 'Escape' && close());\naddEventListener('pageshow', (e) => e.persisted && close());\n// While the browser pictures the old page, keep the menu open in it.\naddEventListener('pageswap', () => { moving = true; });\n\n// A row for this very page: a same-URL navigation gets no page transition, so\n// it is played here, the page opening again out of itself, back at its top.\ncard.addEventListener('click', (e) => {\n const row = e.target.closest('.nav-card__row');\n if (!row || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;\n const url = new URL(row.href);\n if (url.pathname !== location.pathname || url.search !== location.search) return;\n e.preventDefault();\n const update = () => { close(); scrollTo(0, 0); };\n if (document.startViewTransition && !calm()) document.startViewTransition(update);\n else update();\n});\n"
}
}






