fix: hover glass grows with nearness and eases in on real time, not per frame
Hover was a switch at the element's edge on a per-frame spring, so on a 165 Hz screen it lit up in about 0.1 s. It now grows from 48px outside the glass and follows two chained exponentials in milliseconds.
This commit is contained in:
1 parent
4f281715f6
commit
0b7f5728e2
1 file changed
+17
-5
+17
-5
@@ -919,15 +919,27 @@ function shaderScene(scene, art, state) {
|
||||
into.count++;
|
||||
};
|
||||
|
||||
// Per element: hover and press levels on springs, and a stretch along its
|
||||
// own motion (scrolling excluded), like a drop that lags behind.
|
||||
// Per element: a hover level, a press level on a spring, and a stretch
|
||||
// along its own motion (scrolling excluded), like a drop that lags behind.
|
||||
//
|
||||
// Hover grows with nearness, from 48px outside the glass to its edge, and
|
||||
// follows on two chained exponentials in real time: it starts softly, never
|
||||
// jumps, and runs the same on a 60 Hz or a 165 Hz screen.
|
||||
function animate(node, r, fixed) {
|
||||
let m = motion.get(node);
|
||||
const now = performance.now();
|
||||
const cx = r.left + r.width / 2 + (fixed ? 0 : scrollX), cy = r.top + r.height / 2 + (fixed ? 0 : scrollY);
|
||||
if (!m) motion.set(node, m = { cx, cy, sx: 0, sy: 0, hover: { x: 0, v: 0 }, press: { x: 0, v: 0 } });
|
||||
if (!m) motion.set(node, m = { cx, cy, sx: 0, sy: 0, t: now, hover: { x: 0, a: 0 }, press: { x: 0, v: 0 } });
|
||||
const { tx, ty, active: on } = state.pointer;
|
||||
const inside = on && tx >= r.left && tx <= r.right && ty >= r.top && ty <= r.bottom;
|
||||
let moving = spring(m.hover, inside ? 1 : 0, .18, .7);
|
||||
const gap = Math.hypot(Math.max(r.left - tx, 0, tx - r.right), Math.max(r.top - ty, 0, ty - r.bottom));
|
||||
const near = on ? Math.max(0, 1 - gap / 48) : 0, target = near * near * (3 - 2 * near);
|
||||
const dt = Math.min(now - m.t, 64), h = m.hover;
|
||||
m.t = now;
|
||||
const k = PREFS.calm ? 1 : 1 - Math.exp(-dt / (target > h.x ? 70 : 110));
|
||||
h.a += (target - h.a) * k;
|
||||
h.x += (h.a - h.x) * k;
|
||||
let moving = Math.abs(target - h.x) > 1e-3;
|
||||
if (!moving) h.a = h.x = target;
|
||||
moving = spring(m.press, pressed === node || pressed?.closest(".filter") && node.matches(".thumb") ? 1 : 0, .22, .62) || moving;
|
||||
m.sx += (Math.abs(cx - m.cx) - m.sx) * .3;
|
||||
m.sy += (Math.abs(cy - m.cy) - m.sy) * .3;
|
||||
|
||||
Reference in new issue
Block a user