diff --git a/src/components/sections/ShiftableToolsGridSection.tsx b/src/components/sections/ShiftableToolsGridSection.tsx index 45de4ac..5e60c2f 100644 --- a/src/components/sections/ShiftableToolsGridSection.tsx +++ b/src/components/sections/ShiftableToolsGridSection.tsx @@ -262,7 +262,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: const videoRef = useRef(null); const containerRef = useRef(null); const dividerRef = useRef(null); - const afterImgRef = useRef(null); + const clipLayerRef = useRef(null); const handleRef = useRef(null); // High performance refs - completely eliminates per-frame React re-renders! @@ -280,8 +280,8 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: if (dividerRef.current) { dividerRef.current.style.left = `${clamped}%`; } - if (afterImgRef.current) { - afterImgRef.current.style.clipPath = `inset(0 ${100 - clamped}% 0 0)`; + if (clipLayerRef.current) { + clipLayerRef.current.style.clipPath = `inset(0 ${100 - clamped}% 0 0)`; } if (handleRef.current) { handleRef.current.setAttribute('aria-valuenow', `${Math.round(clamped)}`); @@ -317,7 +317,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: // Instant pixel-precise cursor alignment calculation const updateToClientX = useCallback((clientX: number) => { if (!containerRef.current) return; - const rect = containerRef.current.getBoundingClientRect(); + const rect = cachedRectRef.current || containerRef.current.getBoundingClientRect(); if (rect.width <= 0) return; const x = Math.max(0, Math.min(clientX - rect.left, rect.width)); const percent = (x / rect.width) * 100; @@ -362,6 +362,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: if (item.mediaType !== 'comparison') return; if (e.button !== 0 && e.pointerType === 'mouse') return; + e.preventDefault(); e.stopPropagation(); isManualRef.current = true; isPointerDownRef.current = true; @@ -377,6 +378,11 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: // Fallback } + if (containerRef.current) { + const r = containerRef.current.getBoundingClientRect(); + cachedRectRef.current = { left: r.left, width: r.width }; + } + updateToClientX(e.clientX); }; @@ -399,6 +405,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: if (!isPointerDownRef.current) return; e.stopPropagation(); isPointerDownRef.current = false; + cachedRectRef.current = null; if (pointerRafRef.current) { cancelAnimationFrame(pointerRafRef.current); pointerRafRef.current = null; @@ -457,25 +464,29 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: style={{ touchAction: 'pan-y' }} className="relative w-full h-full select-none overflow-hidden bg-slate-950 transform-gpu [backface-visibility:hidden] cursor-ew-resize" > - {/* BEFORE Image (Base layer, fixed scale & position, 0% zoom) */} + {/* Layer 1: AFTER Image (Base layer, fixed scale & position, 0% zoom) */} Before - {/* AFTER Image (Top layer, exact same position & scale, clipped via clip-path) */} - After + > + Before + {/* Glowing Slider Divider Line (pointer-events-none so touching the line allows page scroll) */}
- {/* Badges with Smooth Contrast */} + {/* Badges with Smooth Contrast: BEFORE on left, AFTER on right */}
- - AFTER - BEFORE + + AFTER +
);