Backdrop: four parallax layers, laid out per page, tones per top-level section

Sixteen circles in four layers, big and slow at the back to small
and quicker at the front, each rising by its share of the page's
scroll (none at the page's own speed); how far is measured from the
page's height, so the back layer visibly moves on a long page. Each
path gets its own seeded arrangement. The tone moves on only when a
new top-level section arrives, and eases over 2.4s. Dark shades are
chosen so text passes 4.5:1 however many circles overlap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-30 16:28:55 -05:00
parent e5c14dffa3
commit 2df908f7c4
4 changed files with 154 additions and 98 deletions

View file

@ -163,7 +163,7 @@ export default function Layout() {
// container, and then nothing inside it can be position: sticky
// (a blog post's contents column scrolled away with the page).
<div
className="relative min-h-screen overflow-x-clip"
className="min-h-screen overflow-x-clip"
style={{ "--header-h": `${headerHeight}px` } as React.CSSProperties}
>
<a

View file

@ -1,93 +1,84 @@
/* ═══════════════════════════════════════════════════════════════
PAGE BACKDROP: the circles and their tones (PageBackdrop.tsx)
PAGE BACKDROP: the circles, their layers and shades
(PageBackdrop.tsx places them)
Flat fills only: no blur, no gradient, no glow. Light mode uses
the palette's four palest shades, dark mode its dark shades at
45% opacity over the ink background. Every text token reads at
4.5:1 or better on any of them, even where three overlap (the
lowest, 4.8:1, is the danger red in dark mode).
the palette's four palest shades at 60%, dark mode its dark
shades (two deepened a step) at 30% over the ink background.
Every text token reads at 4.5:1 or better on each shade even at
full strength, so however many circles overlap, text stays
readable (the lowest, 4.66:1, is the danger red on #004552).
═══════════════════════════════════════════════════════════════ */
/* Spans the whole page (Layout's root is its containing block), so
the section circles sit at points down the document; the window
layer inside it is fixed. */
.page-backdrop {
position: absolute;
inset: 0;
z-index: -1;
overflow: hidden; /* the section circles, never the fixed layer */
pointer-events: none;
--pb-opacity: 0.7;
--pb-a: #c2f6ff;
--pb-b: #dfebd6;
--pb-c: #c2ffd6;
--pb-d: #c2fbff;
--pb-e: #dfebd6;
}
.page-backdrop__window {
position: fixed;
inset: 0;
z-index: -1;
overflow: hidden;
pointer-events: none;
--pb-opacity: 0.6;
--pb-0: #c2f6ff;
--pb-1: #dfebd6;
--pb-2: #c2ffd6;
--pb-3: #c2fbff;
}
/* A circle's place: across by its left, down its layer's whole
travel (the window plus how far the layer rises), centered on
that point. */
.page-backdrop__circle {
position: absolute;
width: var(--pb-size);
height: var(--pb-size);
top: calc(var(--pb-top) * (100vh + var(--pb-scroll, 0px) * var(--pb-speed)) - var(--pb-size) / 2);
border-radius: 50%;
opacity: var(--pb-opacity);
transition: background-color 1.4s cubic-bezier(0.16, 1, 0.3, 1);
transition: background-color 2.4s ease-in-out;
}
/* Slow: fixed to the window. */
.page-backdrop__circle--a { width: 70vmax; height: 70vmax; left: -24vmax; top: -16vmax; background: var(--pb-a); --pb-drift: -22vh; }
.page-backdrop__circle--b { width: 50vmax; height: 50vmax; right: -18vmax; top: 34vh; background: var(--pb-b); --pb-drift: -40vh; }
/* Section: placed down the page, moving with it. */
.page-backdrop__circle--c { width: 42vmax; height: 42vmax; left: 34vw; top: 18%; background: var(--pb-c); }
.page-backdrop__circle--d { width: 32vmax; height: 32vmax; left: -8vmax; top: 48%; background: var(--pb-d); }
.page-backdrop__circle--e { width: 36vmax; height: 36vmax; right: -6vmax; top: 74%; background: var(--pb-e); }
/* The slow circles drift up across the whole scroll of the page. */
/* Each layer rises by its share of the page's scroll as the page
scrolls: the back slowest, none as fast as the page. */
@supports (animation-timeline: scroll()) {
.page-backdrop__circle--a,
.page-backdrop__circle--b {
animation: page-backdrop-drift linear both;
.page-backdrop__circle {
animation: page-backdrop-rise linear both;
animation-timeline: scroll(root block);
}
}
@keyframes page-backdrop-drift {
@keyframes page-backdrop-rise {
to {
transform: translateY(var(--pb-drift));
transform: translateY(calc(var(--pb-scroll, 0px) * var(--pb-speed) * -1));
}
}
@media (prefers-reduced-motion: reduce) {
.page-backdrop__circle--a,
.page-backdrop__circle--b {
.page-backdrop__circle {
animation: none;
}
}
/* Tones, one per section in turn: the same shades, swapped around. */
.page-backdrop[data-tone="1"] { --pb-a: #dfebd6; --pb-b: #c2ffd6; --pb-c: #c2f6ff; --pb-d: #dfebd6; --pb-e: #c2fbff; }
.page-backdrop[data-tone="2"] { --pb-a: #c2ffd6; --pb-b: #c2fbff; --pb-c: #dfebd6; --pb-d: #c2f6ff; --pb-e: #c2ffd6; }
.page-backdrop[data-tone="3"] { --pb-a: #c2fbff; --pb-b: #c2f6ff; --pb-c: #c2ffd6; --pb-d: #dfebd6; --pb-e: #c2f6ff; }
/* Dark mode: the dark shades, the same turns. Two blocks as in
index.css: the toggle's choice, or the system's when there is none. */
:root[data-theme="dark"] .page-backdrop { --pb-opacity: 0.45; --pb-a: #004552; --pb-b: #27371b; --pb-c: #004c52; --pb-d: #00521b; --pb-e: #27371b; }
:root[data-theme="dark"] .page-backdrop[data-tone="1"] { --pb-a: #27371b; --pb-b: #004c52; --pb-c: #004552; --pb-d: #27371b; --pb-e: #00521b; }
:root[data-theme="dark"] .page-backdrop[data-tone="2"] { --pb-a: #004c52; --pb-b: #00521b; --pb-c: #27371b; --pb-d: #004552; --pb-e: #004c52; }
:root[data-theme="dark"] .page-backdrop[data-tone="3"] { --pb-a: #00521b; --pb-b: #004552; --pb-c: #004c52; --pb-d: #27371b; --pb-e: #004552; }
/* Dark mode: the dark shades. Two blocks as in index.css: the
toggle's choice, or the system's when there is none. */
:root[data-theme="dark"] .page-backdrop {
--pb-opacity: 0.3;
--pb-0: #004552;
--pb-1: #27371b;
--pb-2: #003f45; /* #004c52 deepened */
--pb-3: #00441a; /* #00521b deepened */
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) .page-backdrop { --pb-opacity: 0.45; --pb-a: #004552; --pb-b: #27371b; --pb-c: #004c52; --pb-d: #00521b; --pb-e: #27371b; }
:root:not([data-theme="light"]) .page-backdrop[data-tone="1"] { --pb-a: #27371b; --pb-b: #004c52; --pb-c: #004552; --pb-d: #27371b; --pb-e: #00521b; }
:root:not([data-theme="light"]) .page-backdrop[data-tone="2"] { --pb-a: #004c52; --pb-b: #00521b; --pb-c: #27371b; --pb-d: #004552; --pb-e: #004c52; }
:root:not([data-theme="light"]) .page-backdrop[data-tone="3"] { --pb-a: #00521b; --pb-b: #004552; --pb-c: #004c52; --pb-d: #27371b; --pb-e: #004552; }
:root:not([data-theme="light"]) .page-backdrop {
--pb-opacity: 0.3;
--pb-0: #004552;
--pb-1: #27371b;
--pb-2: #003f45; /* #004c52 deepened */
--pb-3: #00441a; /* #00521b deepened */
}
}
@media print {
.page-backdrop { display: none; }
.page-backdrop {
display: none;
}
}

View file

@ -1,69 +1,127 @@
/* ═══════════════════════════════════════════════════════════════
PAGE BACKDROP
One background behind every public page: large flat circles in
the palette's light shades (its dark ones in dark mode),
overlapping. Sections paint nothing of their own, so it runs
behind all of them; cards keep their solid surface.
One background behind every public page: flat circles in the
palette's light shades (its dark ones in dark mode), overlapping.
Sections paint nothing of their own, so it runs behind all of
them; cards keep their own raised surface.
Two kinds of circle, for depth as the page scrolls:
slow fixed to the window, drifting up slower than the page
(a CSS scroll-driven animation, PageBackdrop.css)
section placed down the page itself, so they travel with the
sections they sit behind
Without scroll-driven animations, or under reduced motion, the
slow circles simply stay put.
Depth: the circles sit in LAYERS, back to front, each rising at
its own fraction of the page's scroll: big and slow at the back,
small and quicker at the front, none as fast as the page itself.
The rise is a CSS scroll-driven animation (PageBackdrop.css) over
--pb-scroll, the page's scrollable height, which is measured here
whenever the page changes size (no scroll listener). Without
scroll-driven animations, or under reduced motion, they stay put.
As the visitor moves through a page the circles change tone: the
section crossing the middle of the window picks one of TONES (its
place on the page, in turn), and the circles ease to that tone's
colors. Watched with an IntersectionObserver, so nothing runs
while the page sits still. Under reduced motion the change is
instant (index.css stops every transition).
Each page gets its own arrangement: sizes and places come from a
generator seeded with the path, so a page looks the same every
visit and different from its neighbors.
Every text color passes 4.5:1 on every shade used here, overlaps
included, in both modes: the light shades are the palette's
palest, and the dark ones sit at partial opacity.
As the visitor reaches a new section (a top-level one, not one
nested inside another) the circles change tone: each moves to the
next shade in turn, easing slowly. Watched with an
IntersectionObserver; under reduced motion the change is instant
(index.css stops every transition).
Every text color passes 4.5:1 on every shade here, however many
circles overlap (see PageBackdrop.css for the opacities).
═══════════════════════════════════════════════════════════════ */
import { useEffect, useRef } from 'react'
import { useEffect, useMemo, useRef, useState, type CSSProperties } from 'react'
import { useLocation } from 'react-router-dom'
import './PageBackdrop.css'
/** How many tones PageBackdrop.css defines (data-tone 0 to 3). */
const TONES = 4
const SLOW = ['a', 'b']
const SECTION = ['c', 'd', 'e']
/** How many shades PageBackdrop.css defines (--pb-0 to --pb-3). */
const SHADES = 4
/* Back to front: how many circles, how big (vmax), and how much of
the page's scroll the layer rises by. */
const LAYERS = [
{ count: 3, size: [46, 70], speed: 0.14 },
{ count: 4, size: [26, 42], speed: 0.28 },
{ count: 4, size: [16, 26], speed: 0.45 },
{ count: 5, size: [8, 15], speed: 0.65 },
]
type Circle = { layer: number; size: number; left: number; top: number; shade: number; speed: number }
/* A small seeded generator (mulberry32), so a path always draws the
same circles. */
function seeded(text: string) {
let seed = 0
for (const char of text) seed = (Math.imul(seed, 31) + char.charCodeAt(0)) | 0
return () => {
seed = (seed + 0x6d2b79f5) | 0
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
}
function arrange(path: string): Circle[] {
const random = seeded(path)
return LAYERS.flatMap((layer, index) =>
Array.from({ length: layer.count }, (_, i) => ({
layer: index,
size: layer.size[0] + random() * (layer.size[1] - layer.size[0]),
// Spread across the width, and down the layer's full travel:
// one slice of it per circle, placed somewhere in its slice.
left: -15 + random() * 100,
top: (i + random()) / layer.count,
shade: Math.floor(random() * SHADES),
speed: layer.speed,
})),
)
}
export default function PageBackdrop() {
const ref = useRef<HTMLDivElement>(null)
const { pathname } = useLocation()
const [tone, setTone] = useState(0)
const circles = useMemo(() => arrange(pathname), [pathname])
// The page's scrollable height, for how far each layer travels.
useEffect(() => {
const backdrop = ref.current
if (!backdrop) return undefined
const measure = () => {
const scroll = Math.max(0, document.documentElement.scrollHeight - window.innerHeight)
backdrop.style.setProperty('--pb-scroll', `${scroll}px`)
}
measure()
const observer = new ResizeObserver(measure)
observer.observe(document.body)
return () => observer.disconnect()
}, [])
// A new top-level section reaching the window's middle moves the tone on.
useEffect(() => {
const main = document.getElementById('main')
const backdrop = ref.current
if (!main || !backdrop) return undefined
if (!main) return undefined
backdrop.dataset.tone = '0'
setTone(0)
let watched: Element[] = []
// The band crossing the window's middle line sets the tone.
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (!entry.isIntersecting) continue
const index = watched.indexOf(entry.target)
if (index >= 0) backdrop.dataset.tone = String(index % TONES)
if (index >= 0) setTone(index % SHADES)
}
},
{ rootMargin: '-50% 0px -50% 0px', threshold: 0 },
)
// Pages draw their sections as their data arrives, so the list
// is gathered again whenever main's content changes.
// is gathered again whenever main's content changes. Only the
// outermost: a timeline's decades are sections inside one.
const collect = () => {
observer.disconnect()
watched = Array.from(main.querySelectorAll('section'))
watched = Array.from(main.querySelectorAll('section')).filter(
(section) => !section.parentElement?.closest('section'),
)
watched.forEach((section) => observer.observe(section))
}
collect()
@ -83,13 +141,20 @@ export default function PageBackdrop() {
return (
<div ref={ref} className="page-backdrop" aria-hidden="true">
<div className="page-backdrop__window">
{SLOW.map((name) => (
<span key={name} className={`page-backdrop__circle page-backdrop__circle--${name}`} />
))}
</div>
{SECTION.map((name) => (
<span key={name} className={`page-backdrop__circle page-backdrop__circle--${name}`} />
{circles.map((circle, i) => (
<span
key={i}
className={`page-backdrop__circle page-backdrop__circle--${circle.layer}`}
style={
{
'--pb-size': `${circle.size.toFixed(1)}vmax`,
left: `${circle.left.toFixed(1)}vw`,
'--pb-top': circle.top,
'--pb-speed': circle.speed,
background: `var(--pb-${(circle.shade + tone) % SHADES})`,
} as CSSProperties
}
/>
))}
</div>
)