stable state
This commit is contained in:
@@ -39,10 +39,18 @@ export default function GridCanvas() {
|
||||
window.addEventListener("resize", resize);
|
||||
|
||||
// ── mouse tracking (global so it works across the whole page) ────────────
|
||||
const onMove = (e: MouseEvent) => { tx = e.clientX; ty = e.clientY; };
|
||||
const onLeave = () => { tx = -3000; ty = -3000; };
|
||||
window.addEventListener("mousemove", onMove);
|
||||
document.documentElement.addEventListener("mouseleave", onLeave);
|
||||
const onPointerMove = (e: PointerEvent) => { if (e.pointerType === "mouse") { tx = e.clientX; ty = e.clientY; } };
|
||||
const onPointerLeave = (e: PointerEvent) => { if (e.pointerType === "mouse") { tx = -3000; ty = -3000; } };
|
||||
window.addEventListener("pointermove", onPointerMove);
|
||||
document.documentElement.addEventListener("pointerleave", onPointerLeave);
|
||||
|
||||
// ── touch tracking (mobile) ───────────────────────────────────────────────
|
||||
const onTouch = (e: TouchEvent) => {
|
||||
const t = e.touches[0];
|
||||
if (t) { tx = t.clientX; ty = t.clientY; }
|
||||
};
|
||||
window.addEventListener("touchstart", onTouch, { passive: true });
|
||||
window.addEventListener("touchmove", onTouch, { passive: true });
|
||||
|
||||
// ── displacement: pull a point (px,py) toward the cursor ─────────────────
|
||||
const warp = (px: number, py: number): [number, number] => {
|
||||
@@ -159,8 +167,10 @@ export default function GridCanvas() {
|
||||
return () => {
|
||||
cancelAnimationFrame(raf);
|
||||
window.removeEventListener("resize", resize);
|
||||
window.removeEventListener("mousemove", onMove);
|
||||
document.documentElement.removeEventListener("mouseleave", onLeave);
|
||||
window.removeEventListener("pointermove", onPointerMove);
|
||||
document.documentElement.removeEventListener("pointerleave", onPointerLeave);
|
||||
window.removeEventListener("touchstart", onTouch);
|
||||
window.removeEventListener("touchmove", onTouch);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user