Skip to content

Commit f79b8a4

Browse files
moha-bekhclaude
andcommitted
Blur only the panels over the 3D
A panel's blur was redone on every frame it scrolled, over lights that are smooth glows: blurred or not, they look the same. Only a panel over the square the glass is drawn in is blurred now, which page.js tracks for the panels on screen, once a frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fe70a4d commit f79b8a4

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

‎src/page.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export async function initPage({ scenes, shape = 'mark' }) {
8484
$('#scene').hidden = true
8585
return
8686
}
87+
followGlass(scene)
88+
8789
const sections = $$('[data-scene]')
8890
function update() {
8991
const mid = window.innerHeight * 0.5
@@ -242,3 +244,33 @@ function initDebug() {
242244
}
243245
return flags
244246
}
247+
248+
// Blur only the panels the 3D's square is under (style.css, .over-3d). Only
249+
// panels on screen are measured, once a frame.
250+
function followGlass(scene) {
251+
const onScreen = new Set()
252+
const io = new IntersectionObserver((entries) =>
253+
entries.forEach((e) => {
254+
if (e.isIntersecting) onScreen.add(e.target)
255+
else {
256+
onScreen.delete(e.target)
257+
e.target.classList.remove('over-3d')
258+
}
259+
}),
260+
)
261+
$$('.glass, .flow-card').forEach((el) => io.observe(el))
262+
const margin = 24
263+
const tick = () => {
264+
const box = scene.box
265+
for (const el of onScreen) {
266+
let over = false
267+
if (box) {
268+
const r = el.getBoundingClientRect()
269+
over = r.right > box.x - box.half - margin && r.left < box.x + box.half + margin && r.bottom > box.y - box.half - margin && r.top < box.y + box.half + margin
270+
}
271+
if (over !== el.classList.contains('over-3d')) el.classList.toggle('over-3d', over)
272+
}
273+
requestAnimationFrame(tick)
274+
}
275+
requestAnimationFrame(tick)
276+
}

‎src/scene.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,10 @@ export function createScene({ canvas, shape: shapeName = 'mark', reducedMotion =
337337
const half = cur.radius * shape.bound * 1.08 + 3
338338
if (cur.opacity < 0.01 || x + half < 0 || x - half > w || y + half < 0 || y - half > h) {
339339
sinceDraw = Infinity
340+
api.box = null
340341
return
341342
}
343+
api.box = { x, y, half }
342344
fit(cur.radius)
343345
canvas.style.transform = `translate3d(${(x - side / 2).toFixed(1)}px,${(y - side / 2).toFixed(1)}px,0)`
344346

@@ -373,7 +375,9 @@ export function createScene({ canvas, shape: shapeName = 'mark', reducedMotion =
373375
}
374376
requestAnimationFrame(frame)
375377

376-
return {
378+
const api = {
379+
// the square the glass is drawn in, in CSS px, or null when nothing is drawn
380+
box: null,
377381
setState({ anchor = null, fx = 0.5, fy = 0.5, size = 0.3, opacity = 1 }) {
378382
if (anchor !== target.anchor || fx !== target.fx || fy !== target.fy) {
379383
Object.assign(target, { anchor, fx, fy })
@@ -388,4 +392,5 @@ export function createScene({ canvas, shape: shapeName = 'mark', reducedMotion =
388392
target.opacity = opacity
389393
},
390394
}
395+
return api
391396
}

‎src/style.css‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,15 @@ h2 { letter-spacing: -1.8px; margin: 0; font-size: 44px; font-weight: 500; line-
271271
.overview-facts dt { font-size: 13px; font-weight: 500; }
272272
.overview-facts dd { color: var(--muted); margin: 7px 0 0; font-size: 12px; line-height: 1.7; }
273273

274-
/* frosted glass: the WebGL lights show through, blurred */
274+
/* frosted glass: the lights show through. Blurring a smooth glow changes
275+
nothing a reader can see, and redoing it on every frame is what made
276+
scrolling slow, so only a panel over the 3D's square is blurred: page.js
277+
gives it .over-3d while the square is under it. */
275278
.glass {
276279
border-radius: var(--radius-panel);
277280
position: relative;
278281
background: linear-gradient(135deg, #ffffff0f, #ffffff03 55%), #0a0b1033;
279282
border: 1px solid var(--glass-line);
280-
backdrop-filter: var(--glass-blur);
281-
282283
box-shadow: inset 0 1px 0 #ffffff1c, 0 30px 80px -40px #000d;
283284
}
284285
.glass:after, .flow-back:after {
@@ -314,7 +315,7 @@ h2 { letter-spacing: -1.8px; margin: 0; font-size: 44px; font-weight: 500; line-
314315
.flow-glyph { color: var(--tc); font: 30px var(--mono); margin-bottom: 35px; text-shadow: 0 0 18px color-mix(in srgb, var(--tc) 50%, transparent); }
315316
.flow-card small { color: #a9abbb; font: 10px/1.6 var(--mono); letter-spacing: 1px; }
316317
.flow-card strong { display: block; margin: 14px 0 20px; font-size: 23px; font-weight: 400; }
317-
.flow-back { inset: calc(-1 * var(--flow-inset-y)) calc(-1 * var(--flow-inset-x)); opacity: 0; visibility: hidden; transform: translateY(6px); clip-path: inset(var(--flow-inset-y) var(--flow-inset-x) round var(--radius-panel)); pointer-events: none; border: 1px solid #ffffff25; border-radius: var(--radius-panel); background: linear-gradient(135deg, #ffffff0f, #ffffff03 55%), #0a0b10dc; backdrop-filter: var(--glass-blur); box-shadow: inset 0 1px 0 #ffffff1c, 0 20px 50px -25px #000b; transition: opacity .45s ease, transform .55s cubic-bezier(.22, 1, .36, 1), clip-path .55s cubic-bezier(.22, 1, .36, 1), visibility 0s .55s; }
318+
.flow-back { inset: calc(-1 * var(--flow-inset-y)) calc(-1 * var(--flow-inset-x)); opacity: 0; visibility: hidden; transform: translateY(6px); clip-path: inset(var(--flow-inset-y) var(--flow-inset-x) round var(--radius-panel)); pointer-events: none; border: 1px solid #ffffff25; border-radius: var(--radius-panel); background: linear-gradient(135deg, #ffffff0f, #ffffff03 55%), #0a0b10dc; box-shadow: inset 0 1px 0 #ffffff1c, 0 20px 50px -25px #000b; transition: opacity .45s ease, transform .55s cubic-bezier(.22, 1, .36, 1), clip-path .55s cubic-bezier(.22, 1, .36, 1), visibility 0s .55s; }
318319
.flow-card[aria-expanded="true"] .flow-front { opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility 0s .3s; }
319320
.flow-card[aria-expanded="true"] .flow-back { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0); clip-path: inset(0 round var(--radius-panel)); transition-delay: 0s; }
320321
.flow-back > * { opacity: 0; transform: translateY(5px); transition: opacity .3s ease, transform .4s ease; }
@@ -477,7 +478,7 @@ footer a:hover { color: #fff; }
477478
.flow-front, .flow-back { position: relative; grid-area: 1 / 1; inset: auto; min-height: 250px; padding: 24px; border-radius: var(--radius-panel); }
478479
:is(.home, .tool-page) .flow-back { min-height: 250px; }
479480
.flow-back { clip-path: inset(0 round var(--radius-panel)); }
480-
.flow-front, .flow-card .flow-front, .flow-card:nth-child(n) .flow-front { justify-content: flex-start; border: 1px solid var(--glass-line); background: radial-gradient(ellipse at 50% 0, color-mix(in srgb, var(--tc) 8%, transparent), transparent 75%), linear-gradient(135deg, #ffffff0f, #ffffff03 55%), #0a0b10a6; backdrop-filter: var(--glass-blur); box-shadow: inset 0 1px 0 #ffffff1c, 0 -18px 40px -24px #000e; }
481+
.flow-front, .flow-card .flow-front, .flow-card:nth-child(n) .flow-front { justify-content: flex-start; border: 1px solid var(--glass-line); background: radial-gradient(ellipse at 50% 0, color-mix(in srgb, var(--tc) 8%, transparent), transparent 75%), linear-gradient(135deg, #ffffff0f, #ffffff03 55%), #0a0b10a6; box-shadow: inset 0 1px 0 #ffffff1c, 0 -18px 40px -24px #000e; }
481482
.flow-glyph { margin-bottom: 20px; }
482483
:is(.home, .tool-page) .hero { padding-top: 32px; padding-bottom: 40px; }
483484
:is(.home, .tool-page) .hero h1 { font-size: clamp(42px, 10vw, 54px); }
@@ -600,3 +601,5 @@ footer a:hover { color: #fff; }
600601
/* ?debug= switches (page.js, initDebug) */
601602
.debug-fps { position: fixed; right: 12px; bottom: 12px; z-index: 100; padding: 6px 10px; border-radius: var(--radius-small); background: #000c; color: #9fe8c2; font: 12px var(--mono); pointer-events: none; }
602603
.debug-nopanels .glass, .debug-nopanels .flow-back, .debug-nopanels .flow-front { backdrop-filter: none !important; background: #0b0c12 !important; }
604+
605+
.glass.over-3d, .over-3d .flow-back, .over-3d .flow-front { backdrop-filter: var(--glass-blur); }

0 commit comments

Comments
 (0)