diff --git a/src/components/sections/ShiftableToolsGridSection.tsx b/src/components/sections/ShiftableToolsGridSection.tsx
index 1e219c3..96e226f 100644
--- a/src/components/sections/ShiftableToolsGridSection.tsx
+++ b/src/components/sections/ShiftableToolsGridSection.tsx
@@ -184,32 +184,64 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
}}
className="w-full transition-[flex-grow] duration-1000 ease-[cubic-bezier(0.16,1,0.3,1)] will-change-[flex-grow] flex flex-col min-w-0"
>
- {/* Window Container with strictly locked pixel height & landscape aspect (entire card is clickable) */}
-
- {/* GPU-Composited Shadow Elevation Layer */}
-
+ {/* GPU-Composited Shadow Elevation Layer */}
+
- {/* Media Renderer */}
-
+ {/* Media Renderer (Interactive comparison slider with desktop hover + mobile touch handle) */}
+
- {/* Hover Media Type Pill */}
-
-
- {item.mediaType === 'video' && }
- {item.mediaType === 'comparison' && }
- {item.mediaType === 'photo' && }
- {item.mediaType}
-
+ {/* Dedicated Tool Link Pill on top right so sliding never accidentally navigates */}
+
+
TRY TOOL
+
+
+
+ {/* Hover Media Type Pill */}
+
+
+
+ comparison
+
+
-
+ ) : (
+
+ {/* GPU-Composited Shadow Elevation Layer (Opacity-only transition, zero paint thrash) */}
+
+
+ {/* Media Renderer */}
+
+
+ {/* Hover Media Type Pill (Smooth GPU Opacity Transition) */}
+
+
+ {item.mediaType === 'video' && }
+ {item.mediaType === 'photo' && }
+ {item.mediaType}
+
+
+
+ )}
{/* Little Title Below Window (Fixed height, no vertical jumping) */}
(null);
const dividerRef = useRef
(null);
const afterImgRef = useRef(null);
+ const handleRef = useRef(null);
// High performance refs - completely eliminates per-frame React re-renders!
const isManualRef = useRef(false);
- const isInteractedRef = useRef(false);
const isPointerDownRef = useRef(false);
const currentPercentRef = useRef(50);
const animFrameRef = useRef(null);
@@ -251,8 +283,8 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
if (afterImgRef.current) {
afterImgRef.current.style.clipPath = `inset(0 ${100 - clamped}% 0 0)`;
}
- if (containerRef.current) {
- containerRef.current.setAttribute('aria-valuenow', `${Math.round(clamped)}`);
+ if (handleRef.current) {
+ handleRef.current.setAttribute('aria-valuenow', `${Math.round(clamped)}`);
}
}, []);
@@ -274,22 +306,18 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
if (item.mediaType !== 'comparison') return;
if (!isHovered) {
- if (!isInteractedRef.current) {
- if (animFrameRef.current) {
- cancelAnimationFrame(animFrameRef.current);
- animFrameRef.current = null;
- }
- setSliderDOM(50);
+ isManualRef.current = false;
+ if (animFrameRef.current) {
+ cancelAnimationFrame(animFrameRef.current);
+ animFrameRef.current = null;
}
+ setSliderDOM(50);
return;
}
- // If user has already interacted, do not overwrite their position
- if (isInteractedRef.current) return;
-
const startTime = performance.now();
const sweep = (now: number) => {
- if (!isManualRef.current && !isInteractedRef.current) {
+ if (!isManualRef.current) {
const elapsed = (now - startTime) / 1000;
// Calm, breathing oscillation: 1.4 rad/s sine wave with 22% sweep amplitude
const pos = 50 + Math.sin(elapsed * 1.4) * 22;
@@ -308,24 +336,53 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
};
}, [isHovered, item.mediaType, setSliderDOM]);
- // Pointer position tracking:
- // Caches container bounding rect on pointer down to eliminate layout thrashing in pointermove.
- // Updates slider DOM directly in requestAnimationFrame with zero React state calls.
- const handlePointerEnter = (e: React.PointerEvent) => {
- if (item.mediaType !== 'comparison') return;
- const rect = e.currentTarget.getBoundingClientRect();
- cachedRectRef.current = { left: rect.left, width: rect.width };
+ const getContainerRect = () => {
+ if (!containerRef.current) return null;
+ const r = containerRef.current.getBoundingClientRect();
+ return { left: r.left, width: r.width };
};
- const handlePointerDown = (e: React.PointerEvent) => {
+ // Desktop Mouse Movement: Tracks cursor across the entire card effortlessly without clicking
+ const handleContainerPointerEnter = (e: React.PointerEvent) => {
+ if (item.mediaType !== 'comparison') return;
+ if (e.pointerType === 'mouse') {
+ cachedRectRef.current = getContainerRect();
+ }
+ };
+
+ const handleContainerPointerMove = (e: React.PointerEvent) => {
+ if (item.mediaType !== 'comparison') return;
+ if (e.pointerType === 'mouse') {
+ isManualRef.current = true;
+ const clientX = e.clientX;
+ if (pointerRafRef.current) cancelAnimationFrame(pointerRafRef.current);
+ pointerRafRef.current = requestAnimationFrame(() => {
+ let rect = cachedRectRef.current || getContainerRect();
+ cachedRectRef.current = rect;
+ if (!rect || rect.width <= 0) return;
+ const x = Math.max(0, Math.min(clientX - rect.left, rect.width));
+ setSliderDOM((x / rect.width) * 100);
+ });
+ }
+ };
+
+ const handleContainerPointerLeave = () => {
+ if (isPointerDownRef.current) return;
+ isManualRef.current = false;
+ cachedRectRef.current = null;
+ if (pointerRafRef.current) {
+ cancelAnimationFrame(pointerRafRef.current);
+ pointerRafRef.current = null;
+ }
+ };
+
+ // Dedicated Drag Handlers for Center Arrow Handle (Works on mobile touch & desktop click-drag)
+ const handleHandlePointerDown = (e: React.PointerEvent) => {
if (item.mediaType !== 'comparison') return;
if (e.button !== 0 && e.pointerType === 'mouse') return;
- // Prevent container click bubbling and vertical scrolling
e.stopPropagation();
-
isManualRef.current = true;
- isInteractedRef.current = true;
isPointerDownRef.current = true;
if (animFrameRef.current) {
@@ -339,19 +396,18 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
// Fallback
}
- const rect = e.currentTarget.getBoundingClientRect();
- cachedRectRef.current = { left: rect.left, width: rect.width };
-
- const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
- const percent = (x / rect.width) * 100;
- setSliderDOM(percent);
+ const rect = getContainerRect();
+ cachedRectRef.current = rect;
+ if (rect && rect.width > 0) {
+ const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
+ setSliderDOM((x / rect.width) * 100);
+ }
};
- const handlePointerMove = (e: React.PointerEvent) => {
- if (item.mediaType !== 'comparison') return;
+ const handleHandlePointerMove = (e: React.PointerEvent) => {
if (!isPointerDownRef.current) return;
+ e.stopPropagation();
isManualRef.current = true;
- isInteractedRef.current = true;
const clientX = e.clientX;
if (pointerRafRef.current) {
@@ -359,22 +415,18 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
}
pointerRafRef.current = requestAnimationFrame(() => {
- let rect = cachedRectRef.current;
- if (!rect && containerRef.current) {
- const r = containerRef.current.getBoundingClientRect();
- rect = { left: r.left, width: r.width };
- cachedRectRef.current = rect;
- }
+ let rect = cachedRectRef.current || getContainerRect();
+ cachedRectRef.current = rect;
if (!rect || rect.width <= 0) return;
const x = Math.max(0, Math.min(clientX - rect.left, rect.width));
- const percent = (x / rect.width) * 100;
- setSliderDOM(percent);
+ setSliderDOM((x / rect.width) * 100);
});
};
- const handlePointerUp = (e: React.PointerEvent) => {
- if (item.mediaType !== 'comparison') return;
+ const handleHandlePointerUp = (e: React.PointerEvent) => {
+ if (!isPointerDownRef.current) return;
+ e.stopPropagation();
isPointerDownRef.current = false;
cachedRectRef.current = null;
if (pointerRafRef.current) {
@@ -388,26 +440,15 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
}
};
- const handlePointerLeave = () => {
- if (isPointerDownRef.current) return; // Keep tracking if pointer capture is active
- cachedRectRef.current = null;
- if (pointerRafRef.current) {
- cancelAnimationFrame(pointerRafRef.current);
- pointerRafRef.current = null;
- }
- };
-
const handleKeyDown = (e: React.KeyboardEvent) => {
if (item.mediaType !== 'comparison') return;
const step = e.shiftKey ? 10 : 2;
if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') {
e.preventDefault();
- isInteractedRef.current = true;
isManualRef.current = true;
setSliderDOM(currentPercentRef.current - step);
} else if (e.key === 'ArrowRight' || e.key === 'ArrowUp') {
e.preventDefault();
- isInteractedRef.current = true;
isManualRef.current = true;
setSliderDOM(currentPercentRef.current + step);
}
@@ -437,8 +478,11 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
return (
{/* BEFORE Image (Base layer, fixed scale & position, 0% zoom) */}
![]()
- {/* Circular Grab Handle with Before/After Arrow Cue & Touch Padding - Dedicated Drag Trigger with Pointer Capture */}
+ {/* Circular Grab Handle with Before/After Arrow Cue & Touch Hit Area */}
{
- e.preventDefault();
- e.stopPropagation();
- }}
+ ref={handleRef}
+ onPointerDown={handleHandlePointerDown}
+ onPointerMove={handleHandlePointerMove}
+ onPointerUp={handleHandlePointerUp}
+ onPointerCancel={handleHandlePointerUp}
onKeyDown={handleKeyDown}
role="slider"
aria-label="Before and after comparison slider"
@@ -484,7 +525,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
aria-valuenow={50}
tabIndex={0}
style={{ touchAction: 'none' }}
- className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-8 h-8 rounded-full bg-white shadow-xl border border-slate-200/90 flex items-center justify-center text-xs font-bold text-blue-600 pointer-events-auto cursor-ew-resize touch-none before:absolute before:-inset-3 before:content-['']"
+ className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-9 h-9 sm:w-10 sm:h-10 rounded-full bg-white shadow-xl border border-slate-200/90 flex items-center justify-center text-xs font-bold text-blue-600 pointer-events-auto cursor-ew-resize touch-none before:absolute before:-inset-4 before:content-[''] hover:scale-110 active:scale-95 transition-transform"
>
↔
diff --git a/src/components/ui/CardBeforeAfterSlider.tsx b/src/components/ui/CardBeforeAfterSlider.tsx
index d3ab408..a58d313 100644
--- a/src/components/ui/CardBeforeAfterSlider.tsx
+++ b/src/components/ui/CardBeforeAfterSlider.tsx
@@ -145,11 +145,21 @@ export function CardBeforeAfterSlider({
}
}, []);
+ const handleContainerPointerDown = useCallback(
+ (e: React.PointerEvent
) => {
+ // On desktop with mouse, clicking anywhere on the card moves the split
+ if (e.pointerType !== 'mouse' || e.button !== 0) return;
+ handlePointerDown(e);
+ },
+ [handlePointerDown]
+ );
+
return (
) => {
if (e.button !== 0 && e.pointerType === 'mouse') return;
e.stopPropagation();
@@ -105,6 +105,12 @@ export function Cinematic3DComparison({
}
};
+ const handleContainerPointerDown = (e: React.PointerEvent
) => {
+ // On desktop with mouse, clicking anywhere on the stage moves the slider
+ if (e.pointerType !== 'mouse' || e.button !== 0) return;
+ handlePointerDown(e);
+ };
+
const handlePointerMove = (e: React.PointerEvent) => {
if (!isPointerDownRef.current) return;
e.stopPropagation();
@@ -167,6 +173,7 @@ export function Cinematic3DComparison({
{/* 3D Kinetic Tilt Stage - Allows smooth page scrolling when touching anywhere except the arrows handle */}