Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions quartz/components/scripts/archiveGate.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<HTMLElement>(".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<HTMLElement>("#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")
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions quartz/components/styles/archiveGate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down