feat: smooth expansions and a time-smoothed scroll dim

Changelog expand, filter switch and note folds ease between heights on iOS's sheet curve with staggered entries; the glass follows at full rate. Scroll dimming follows a smoothstep target through a 320 ms exponential. The CSS light variables are skipped when the shader draws the glass.
This commit is contained in:
Flechazo committed 2026-10-25 09:59:28 +08:00
1 parent f4017387b0
commit 09fd1a8cd5
3 files changed
+48 -13

No files matched your search

+2 -2
View File
@@ -190,8 +190,8 @@ html.liquid .stamp { color: rgba(246, 240, 255, .66); }
.notes ul { margin: 0; padding-left: 1.1em; color: var(--muted); }
.notes li + li { margin-top: 4px; }
.notes li::marker { color: var(--faint); }
.notes .fold { max-height: 8.6em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); transition: max-height .5s var(--ease); }
.notes .fold.open { max-height: 60em; -webkit-mask-image: none; mask-image: none; }
.notes .fold { max-height: 8.6em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
.notes .fold.open { max-height: none; -webkit-mask-image: none; mask-image: none; }
.link { font: inherit; font-size: 13px; color: var(--blade); background: none; border: 0; padding: 0; margin-top: 8px; cursor: pointer; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
+44 -9
View File
@@ -242,7 +242,7 @@ function renderNotes(card, component, version) {
if (fold.scrollHeight <= fold.clientHeight + 4) { fold.classList.add("open"); return; }
const toggle = el("button", { type: "button", class: "link toggle", text: t("expand") });
toggle.addEventListener("click", () => {
toggle.textContent = t(fold.classList.toggle("open") ? "collapse" : "expand");
morph(fold, () => { toggle.textContent = t(fold.classList.toggle("open") ? "collapse" : "expand"); });
});
box.append(toggle);
});
@@ -275,6 +275,29 @@ function renderTimeline() {
observeReveal();
}
// Apple-style expansion: the box eases from its old height to the new one on
// iOS's sheet curve while new content rises in with a short stagger. The
// glass follows the box's live rectangle.
const SMOOTH = "cubic-bezier(.32, .72, 0, 1)";
let glassAwake = 0;
function morph(box, mutate, arriving = () => []) {
if (PREFS.calm || !box.animate) { mutate(); return; }
const from = box.getBoundingClientRect().height;
box.getAnimations().forEach(a => a.cancel());
mutate();
const to = box.getBoundingClientRect().height;
const duration = Math.min(820, 420 + Math.abs(to - from) * .25);
glassAwake = performance.now() + duration + 200;
if (Math.abs(to - from) > 1) {
const frame = h => ({ height: `${h}px`, maxHeight: "none", overflow: "clip", boxSizing: "border-box" });
box.animate([frame(from), frame(to)], { duration, easing: SMOOTH });
}
arriving().slice(0, 14).forEach((node, i) => node.animate(
[{ opacity: 0, transform: "translateY(14px)", filter: "blur(6px)" }, { opacity: 1, transform: "none", filter: "blur(0)" }],
{ duration: 560, delay: 60 + i * 40, easing: SMOOTH, fill: "backwards" },
));
}
let toastTimer = 0;
async function copyText(text) {
try {
@@ -854,7 +877,7 @@ function shaderScene(scene, art, state) {
requestAnimationFrame(draw);
if (document.hidden) { last = 0; return; }
// Idle: nothing moves but the scene's slow light, so redraw sparingly.
const idle = !wasMoving && now - active > 700;
const idle = !wasMoving && now - active > 700 && now > glassAwake;
if (idle && now - lastDraw < 48) return;
if (!idle) {
if (last && now - last > 30) { if (++slow > 40 && quality > .55) { quality *= .85; slow = 0; } } else slow = Math.max(0, slow - 1);
@@ -902,7 +925,7 @@ function sceneLight() {
const scene = $(".scene");
const fine = matchMedia("(pointer: fine)");
const pointer = { x: innerWidth / 2, y: innerHeight / 3, tx: innerWidth / 2, ty: innerHeight / 3, active: false };
let frame = 0, settle = 0;
let frame = 0, settle = 0, lastT = 0;
const state = { pointer, rect: { x: 0, y: 0, w: 1, h: 1 }, dim: 0 };
const art = new Image();
@@ -930,8 +953,15 @@ function sceneLight() {
const by = still || !fine.matches ? 0 : -(pointer.y / h - .5) * 18;
scene.style.setProperty("--bx", `${bx.toFixed(1)}px`);
scene.style.setProperty("--by", `${by.toFixed(1)}px`);
state.dim = Math.min(.55, scrollY / (h * 1.4) * .55);
document.documentElement.style.setProperty("--dim", state.dim.toFixed(3));
// Dim along a smoothstep of scroll, then follow it with a time-based
// exponential, so a fast fling darkens gradually instead of in a jump.
const now = performance.now(), dt = lastT ? Math.min(now - lastT, 64) : 16;
lastT = now;
const s = Math.min(1, scrollY / (h * 1.8)), target = .5 * s * s * (3 - 2 * s);
state.dim += (target - state.dim) * (still ? 1 : 1 - Math.exp(-dt / 320));
const dimming = Math.abs(target - state.dim) > .002;
if (!dimming) lastT = 0;
document.documentElement.style.setProperty("--dim", state.dim.toFixed(4));
const tl = project(0, 0, bx, by), br = project(1, 1, bx, by);
state.rect = { x: tl.x, y: tl.y, w: br.x - tl.x, h: br.y - tl.y };
const points = LIGHTS.map(l => ({ ...project(l.u, l.v, bx, by), w: l.w }));
@@ -940,7 +970,8 @@ function sceneLight() {
scene.style.setProperty(`--l${i + 1}y`, `${(p.y / h * 100).toFixed(2)}%`);
});
const reach = Math.hypot(w, h);
for (const glass of $$(".glass")) {
// The shader lights its own glass; these variables feed the CSS fallback.
if (!document.documentElement.classList.contains("liquid")) for (const glass of $$(".glass")) {
const r = glass.getBoundingClientRect();
if (r.bottom < -100 || r.top > h + 100) continue;
const cx = r.left + r.width / 2, cy = r.top + r.height / 2;
@@ -962,7 +993,8 @@ function sceneLight() {
glass.style.setProperty("--py", `${(pointer.ty - r.top).toFixed(0)}px`);
}
}
if (Math.abs(pointer.tx - pointer.x) + Math.abs(pointer.ty - pointer.y) > .5 || --settle > 0) schedule();
if (dimming) glassAwake = Math.max(glassAwake, now + 100);
if (dimming || Math.abs(pointer.tx - pointer.x) + Math.abs(pointer.ty - pointer.y) > .5 || --settle > 0) schedule();
}
const schedule = () => { if (!frame) frame = requestAnimationFrame(update); };
@@ -1046,10 +1078,13 @@ function bind() {
state.filter = button.dataset.filter;
$$(".filter button").forEach(b => b.setAttribute("aria-selected", String(b === button)));
placeThumb();
renderTimeline();
morph($(".log"), renderTimeline, () => $$("#timeline > .entry:not(.hidden)"));
sceneLight.refresh?.();
}));
$("#more").addEventListener("click", () => { state.expanded = true; renderTimeline(); sceneLight.refresh?.(); });
$("#more").addEventListener("click", () => {
morph($(".log"), () => { state.expanded = true; renderTimeline(); }, () => $$("#timeline > .entry").slice(PAGE));
sceneLight.refresh?.();
});
$$(".hero, .card, .log, .verify").forEach(n => n.classList.add("reveal"));
observeReveal();
}
+2 -2
View File
@@ -9,8 +9,8 @@
<meta name="theme-color" content="#140a24">
<link rel="icon" href="/assets/icon.svg" type="image/svg+xml">
<link rel="preload" href="/assets/bg.webp" as="image" type="image/webp">
<link rel="stylesheet" href="/assets/app.css?v=10">
<script src="/assets/app.js?v=10" defer></script>
<link rel="stylesheet" href="/assets/app.css?v=11">
<script src="/assets/app.js?v=11" defer></script>
</head>
<body>
<div class="scene" aria-hidden="true">