From 6506f65b1e7a31cd22bd697fe5c78e69b28dfab6 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Wed, 30 Sep 2026 16:35:25 -0500 Subject: [PATCH] Backdrop parallax in Firefox: a passive scroll fallback Where scroll-driven animations are missing, a passive scroll handler writes the scroll position to --pb-y at most once a frame and the CSS moves each layer by its share, matching the scroll-timeline version. Off under reduced motion. Co-Authored-By: Claude Opus 5.5 --- src/components/PageBackdrop.css | 11 ++++++++++- src/components/PageBackdrop.tsx | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/components/PageBackdrop.css b/src/components/PageBackdrop.css index 02fc866..ff21d1d 100644 --- a/src/components/PageBackdrop.css +++ b/src/components/PageBackdrop.css @@ -46,6 +46,13 @@ } } +/* The same rise where scroll-driven animations are missing: the + scroll position arrives as --pb-y from PageBackdrop.tsx. */ +.page-backdrop[data-parallax="script"] .page-backdrop__circle { + transform: translateY(calc(var(--pb-y, 0px) * var(--pb-speed) * -1)); + will-change: transform; +} + @keyframes page-backdrop-rise { to { transform: translateY(calc(var(--pb-scroll, 0px) * var(--pb-speed) * -1)); @@ -53,8 +60,10 @@ } @media (prefers-reduced-motion: reduce) { - .page-backdrop__circle { + .page-backdrop__circle, + .page-backdrop[data-parallax="script"] .page-backdrop__circle { animation: none; + transform: none; } } diff --git a/src/components/PageBackdrop.tsx b/src/components/PageBackdrop.tsx index 80e70a5..55b59ab 100644 --- a/src/components/PageBackdrop.tsx +++ b/src/components/PageBackdrop.tsx @@ -11,8 +11,11 @@ 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. + whenever the page changes size. Browsers without scroll-driven + animations (Firefox, for now) get the same motion from a passive + scroll handler instead, which writes the scroll position to one + CSS variable, --pb-y, at most once a frame; the CSS does the rest. + Under reduced motion they stay put either way. Each page gets its own arrangement: sizes and places come from a generator seeded with the path, so a page looks the same every @@ -95,6 +98,32 @@ export default function PageBackdrop() { return () => observer.disconnect() }, []) + // Where scroll-driven animations are missing: the scroll position, + // once a frame at most, into --pb-y (PageBackdrop.css moves each + // layer by its share of it). + useEffect(() => { + const backdrop = ref.current + if (!backdrop || CSS.supports('animation-timeline: scroll()')) return undefined + if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return undefined + + backdrop.dataset.parallax = 'script' + let frame = 0 + const update = () => { + frame = 0 + backdrop.style.setProperty('--pb-y', `${window.scrollY}px`) + } + const onScroll = () => { + if (!frame) frame = requestAnimationFrame(update) + } + update() + window.addEventListener('scroll', onScroll, { passive: true }) + return () => { + window.removeEventListener('scroll', onScroll) + cancelAnimationFrame(frame) + delete backdrop.dataset.parallax + } + }, []) + // A new top-level section reaching the window's middle moves the tone on. useEffect(() => { const main = document.getElementById('main')