From 6136b3f6759fbf246c4a5db619800e0cdd92cc36 Mon Sep 17 00:00:00 2001 From: komeno Date: Tue, 1 Dec 2026 00:15:23 +0900 Subject: [PATCH] Turn off the photo tilt on touch devices Only run it where the primary pointer can hover (mouse or trackpad), and ignore touch and pen input even there, so phones and tablets show a still photo. Drops the touch-drag handling and touch-action rule. Co-Authored-By: Claude Opus 5.5 --- quartz/components/scripts/tilt.inline.ts | 18 ++++++------------ quartz/components/styles/tilt.scss | 3 --- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/quartz/components/scripts/tilt.inline.ts b/quartz/components/scripts/tilt.inline.ts index 517ea0343127..5e4f84461ce8 100644 --- a/quartz/components/scripts/tilt.inline.ts +++ b/quartz/components/scripts/tilt.inline.ts @@ -5,8 +5,8 @@ // and the shadow underneath slides opposite the tilt. Motion runs on springs (after the // HoloCard component on reactbits.dev) so it eases in and settles instead of snapping. // -// Touch screens have no hover, so there the card follows a finger while it's pressed -// and lets go on release; a vertical swipe still scrolls the page (touch-action: pan-y). +// Desktop only: it runs where the primary pointer can hover (a mouse or trackpad), and +// ignores touch and pen input there too, so phones and tablets get a still photo. const PERSPECTIVE = 1100 // px const TILT_MAX = 12 // deg at the card's edge @@ -87,7 +87,7 @@ function setupTilt(root: HTMLElement) { Math.abs(s.tiltY - targetY) + Math.abs(s.lift - targetLift) * 40 calm = motion > 0.02 ? 0 : calm + dt - // Sleep once the card has settled and nobody is touching it. + // Sleep once the card has settled and the pointer has left. if (!pointer.inside && calm > 0.3) { card.style.transform = "" return @@ -103,8 +103,7 @@ function setupTilt(root: HTMLElement) { } const track = (e: PointerEvent) => { - // A finger only steers while it's pressed; otherwise a stray move would stick. - if (e.pointerType === "touch" && e.type === "pointermove" && !e.buttons) return + if (e.pointerType !== "mouse") return const rect = root.getBoundingClientRect() pointer.x = clamp((e.clientX - rect.left) / rect.width, 0, 1) pointer.y = clamp((e.clientY - rect.top) / rect.height, 0, 1) @@ -112,32 +111,27 @@ function setupTilt(root: HTMLElement) { wake() } - const leave = (e: PointerEvent) => { - // A mouse button release keeps hovering; only a lifted finger lets go. - if (e.type === "pointerup" && e.pointerType !== "touch") return + const leave = () => { pointer.inside = false wake() } root.addEventListener("pointerenter", track) root.addEventListener("pointermove", track) - root.addEventListener("pointerdown", track) root.addEventListener("pointerleave", leave) - root.addEventListener("pointerup", leave) root.addEventListener("pointercancel", leave) window.addCleanup(() => { cancelAnimationFrame(raf) root.removeEventListener("pointerenter", track) root.removeEventListener("pointermove", track) - root.removeEventListener("pointerdown", track) root.removeEventListener("pointerleave", leave) - root.removeEventListener("pointerup", leave) root.removeEventListener("pointercancel", leave) }) } document.addEventListener("nav", () => { if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return + if (!window.matchMedia("(hover: hover) and (pointer: fine)").matches) return document.querySelectorAll("[data-tilt]").forEach(setupTilt) }) diff --git a/quartz/components/styles/tilt.scss b/quartz/components/styles/tilt.scss index dbf587b77e2e..05b25a6d93af 100644 --- a/quartz/components/styles/tilt.scss +++ b/quartz/components/styles/tilt.scss @@ -4,9 +4,6 @@ // Each root sets --tilt-radius to its corner radius. [data-tilt] { position: relative; - // Horizontal drags tilt the photo on touch screens; vertical ones still scroll. - touch-action: pan-y; - -webkit-tap-highlight-color: transparent; } // Hidden at rest; fades in and slides opposite the tilt while the card is lifted.