diff --git a/quartz/components/scripts/archiveGate.inline.ts b/quartz/components/scripts/archiveGate.inline.ts index 98dce62d7890..b564817e2ef2 100644 --- a/quartz/components/scripts/archiveGate.inline.ts +++ b/quartz/components/scripts/archiveGate.inline.ts @@ -8,6 +8,8 @@ const SCROLL_MS = 850 // Long enough to see the door swing wide (its transition is 0.8s) before the page changes. const ENTER_MS = 650 +// Folding: how long the drawing takes to fade out before the scene collapses. +const FADE_OUT_MS = 450 const EASE = "cubic-bezier(.45,0,.4,1)" @@ -58,6 +60,7 @@ document.addEventListener("nav", () => { cue?.setAttribute("aria-expanded", "false") } + let fading: Animation | undefined let glide: Animation[] = [] const stopScroll = () => { glide.forEach((animation) => animation.cancel()) @@ -105,15 +108,47 @@ document.addEventListener("nav", () => { // Both ways the page jumps at once and glideBy() turns the jump into a smooth slide: a // smooth scroll would stutter here, competing with the layout change and the fade-in. if (section.hasAttribute("data-revealed")) { + if (fading) return // already on its way out // Folding shortens the page: keep the cue where it is on screen, and if the browser // has to pull the page up (at its end), slide that too. - const before = cue.getBoundingClientRect().top - fold() - window.scrollTo({ - top: window.scrollY + (cue.getBoundingClientRect().top - before), - behavior: "instant", - }) - glideBy(before - cue.getBoundingClientRect().top) + const collapse = () => { + const before = cue.getBoundingClientRect().top + fold() + window.scrollTo({ + top: window.scrollY + (cue.getBoundingClientRect().top - before), + behavior: "instant", + }) + glideBy(before - cue.getBoundingClientRect().top) + } + const head = section.querySelector(".archive-head") + if (reduceMotion.matches || !head) return collapse() + // The drawing fades out first (the fade-in reversed), and only then is the scene + // folded away. The chevron flips at once (data-folding, see archiveGate.scss). + section.setAttribute("data-folding", "") + cue.setAttribute("aria-expanded", "false") + // The footer's copyright goes with it (folded, the page ends at the cue; see the + // footer rule in archiveGate.scss), so it fades out alongside. + const timing = { duration: FADE_OUT_MS, easing: "ease", fill: "forwards" } as const + const footer = document.querySelector("#quartz-body > footer") + const animation = head.animate( + [ + { opacity: 1, translate: "0 0" }, + { opacity: 0, translate: "0 0.75rem" }, + ], + timing, + ) + const footerFade = footer?.animate([{ opacity: 1 }, { opacity: 0 }], timing) + fading = animation + animation.finished + .then(() => { + section.removeAttribute("data-folding") + collapse() + // Hidden now, so dropping the held end state shows nothing. + animation.cancel() + footerFade?.cancel() + fading = undefined + }) + .catch(() => {}) return } reveal("now") @@ -148,6 +183,11 @@ document.addEventListener("nav", () => { window.addCleanup(() => { stopScroll() + fading?.cancel() + document + .querySelector("#quartz-body > footer") + ?.getAnimations() + .forEach((a) => a.cancel()) window.clearTimeout(entering) door.removeEventListener("click", onDoor) cue?.removeEventListener("click", onCue) diff --git a/quartz/components/styles/archiveGate.scss b/quartz/components/styles/archiveGate.scss index 1f2f37334ced..e4568ade88f4 100644 --- a/quartz/components/styles/archiveGate.scss +++ b/quartz/components/styles/archiveGate.scss @@ -151,8 +151,9 @@ body:has(.article-archive:not([data-revealed]):not(:target)) #quartz-body > foot stroke-linejoin: round; transition: rotate 0.4s cubic-bezier(0.3, 0.7, 0.3, 1); } -// Folded, the chevron points down to what is hidden; revealed, it flips to point up. -.article-archive[data-revealed] .archive-cue-chevron, +// Folded, the chevron points down to what is hidden; revealed, it flips to point up. While +// the drawing fades out on its way to folding (data-folding), it already points down. +.article-archive[data-revealed]:not([data-folding]) .archive-cue-chevron, .article-archive:target .archive-cue-chevron { rotate: 180deg; }