From 6a0bb61c053d3a5fd08d31d363f616ad7a9ff64d Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Wed, 4 Nov 2026 12:00:17 +0530 Subject: [PATCH] fix: streamline tool page to single upload and single compare, make vertical-horizontal transitions fluid and seamless --- content/templates/tool.json | 67 +------------- .../sections/BeforeAfterSection.tsx | 2 +- .../CinematicHorizontalScrollSection.tsx | 74 ++++++++++----- src/components/sections/HeroSection.tsx | 90 +++++++------------ src/components/sections/TryItWidget.tsx | 41 +++------ 5 files changed, 102 insertions(+), 172 deletions(-) diff --git a/content/templates/tool.json b/content/templates/tool.json index ca9e20d..cd82dcf 100644 --- a/content/templates/tool.json +++ b/content/templates/tool.json @@ -16,8 +16,8 @@ "type": "beforeAfter", "props": { "title": { - "en": "Real Before & After Results", - "hi": "वास्तविक पहले और बाद के परिणाम" + "en": "Real Before & After Result", + "hi": "वास्तविक पहले और बाद का परिणाम" }, "subtitle": { "en": "Inspect sub-pixel neural transformation details with the interactive comparison slider.", @@ -25,69 +25,6 @@ }, "items": "{{tool.content.examples}}" } - }, - { - "id": "tool-handoff", - "type": "appHandoff", - "props": { - "toolRef": "{{tool.id}}", - "appRef": "{{tool.homeApp}}" - } - }, - { - "id": "tool-steps", - "type": "steps", - "props": { - "title": { - "en": "How It Works", - "hi": "यह कैसे काम करता है" - }, - "items": "{{tool.content.steps}}" - } - }, - { - "id": "tool-availability", - "type": "availability", - "props": { - "toolRef": "{{tool.id}}" - } - }, - { - "id": "tool-faq", - "type": "faq", - "props": { - "title": { - "en": "Frequently Asked Questions", - "hi": "अक्सर पूछे जाने वाले प्रश्न" - }, - "items": "{{tool.content.faqs}}" - } - }, - { - "id": "tool-related", - "type": "relatedTools", - "props": { - "toolRef": "{{tool.id}}", - "limit": 4 - } - }, - { - "id": "tool-cta", - "type": "ctaBanner", - "props": { - "title": { - "en": "Ready for 4K Lossless Processing?", - "hi": "क्या आप 4K लॉसलेस प्रोसेसिंग के लिए तैयार हैं?" - }, - "subtitle": { - "en": "Open {{tool.name}} in {{tool.homeApp.name}} on your phone.", - "hi": "अपने फोन पर {{tool.homeApp.name}} में {{tool.name}} खोलें।" - }, - "primaryCta": { - "label": { "en": "Open in Mobile App", "hi": "मोबाइल ऐप में खोलें" }, - "href": "/go/{{tool.slug}}/{{tool.homeApp.slug}}" - } - } } ] } diff --git a/src/components/sections/BeforeAfterSection.tsx b/src/components/sections/BeforeAfterSection.tsx index 0304497..4c53546 100644 --- a/src/components/sections/BeforeAfterSection.tsx +++ b/src/components/sections/BeforeAfterSection.tsx @@ -40,7 +40,7 @@ export function BeforeAfterSection({ )} -
1 ? 'md:grid-cols-2' : 'max-w-2xl mx-auto'} gap-8 sm:gap-10`}> +
1 ? 'md:grid-cols-2' : 'max-w-3xl mx-auto'} gap-8 sm:gap-10`}> {items.map((item, idx) => (
(null); const trackRef = useRef(null); - const [translateX, setTranslateX] = useState(0); + + const targetXRef = useRef(0); + const currentXRef = useRef(0); + const animFrameRef = useRef(0); + const isLoopRunningRef = useRef(false); + const [activeIndex, setActiveIndex] = useState(0); const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(true); - // Synchronize horizontal track position with vertical scroll progress through sticky section + // High-performance, responsive LERP animation loop to smooth wheel notches into liquid momentum + const startLerpLoop = useCallback(() => { + if (isLoopRunningRef.current) return; + isLoopRunningRef.current = true; + + const loop = () => { + const track = trackRef.current; + if (!track) { + isLoopRunningRef.current = false; + return; + } + + const diff = targetXRef.current - currentXRef.current; + + if (Math.abs(diff) > 0.4) { + // Responsive 0.28 damping factor: silky smoothing with zero perceptible lag + currentXRef.current += diff * 0.28; + track.style.transform = `translate3d(-${currentXRef.current.toFixed(2)}px, 0, 0)`; + animFrameRef.current = requestAnimationFrame(loop); + } else { + currentXRef.current = targetXRef.current; + track.style.transform = `translate3d(-${currentXRef.current.toFixed(2)}px, 0, 0)`; + isLoopRunningRef.current = false; + } + }; + + animFrameRef.current = requestAnimationFrame(loop); + }, []); + + // Compute fluid horizontal translation directly from vertical scroll progress const updateTranslation = useCallback(() => { const container = containerRef.current; const track = trackRef.current; @@ -56,7 +90,9 @@ export function CinematicHorizontalScrollSection({ const totalScrollable = container.offsetHeight - window.innerHeight; if (totalScrollable <= 0) return; - // Progress: 0.0 when section top hits viewport top, 1.0 when bottom unpins + // Direct proportional progress through the sticky section [0.0, 1.0] + // 0.0: Card 0 centered, exactly as section pins + // 1.0: Final card centered, seamlessly unpins into vertical scroll const progress = Math.max(0, Math.min(1, -rect.top / totalScrollable)); const cards = Array.from(track.querySelectorAll('article')); @@ -66,9 +102,10 @@ export function CinematicHorizontalScrollSection({ const lastCenter = cards[cards.length - 1].offsetLeft + cards[cards.length - 1].offsetWidth / 2; const maxDistance = lastCenter - firstCenter; - const targetX = progress * maxDistance; - setTranslateX(targetX); + targetXRef.current = progress * maxDistance; + startLerpLoop(); + // Sync active card index and button states const active = Math.min( cards.length - 1, Math.max(0, Math.round(progress * (cards.length - 1))) @@ -77,18 +114,11 @@ export function CinematicHorizontalScrollSection({ setCanScrollLeft(progress > 0.02); setCanScrollRight(progress < 0.98); - }, []); + }, [startLerpLoop]); useEffect(() => { - let ticking = false; const handleScroll = () => { - if (!ticking) { - requestAnimationFrame(() => { - updateTranslation(); - ticking = false; - }); - ticking = true; - } + updateTranslation(); }; updateTranslation(); @@ -98,10 +128,11 @@ export function CinematicHorizontalScrollSection({ return () => { window.removeEventListener('scroll', handleScroll); window.removeEventListener('resize', handleScroll); + if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current); }; }, [updateTranslation, items.length]); - // Slide between cards using side arrows + // Slide smoothly between cards using side arrows const scrollDirection = (direction: 'left' | 'right') => { const container = containerRef.current; if (!container) return; @@ -113,10 +144,11 @@ export function CinematicHorizontalScrollSection({ const rect = container.getBoundingClientRect(); const containerTopInDoc = window.scrollY + rect.top; - const currentProgress = Math.max(0, Math.min(1, -rect.top / totalScrollable)); + const progress = Math.max(0, Math.min(1, -rect.top / totalScrollable)); + const currentCardIndex = Math.min( cardsCount - 1, - Math.max(0, Math.round(currentProgress * (cardsCount - 1))) + Math.max(0, Math.round(progress * (cardsCount - 1))) ); let targetIndex = currentCardIndex; @@ -137,7 +169,7 @@ export function CinematicHorizontalScrollSection({ if (!items.length) return null; - // Vertical scroll distance: 100vh base + 85vh per additional card + // Fluid vertical scroll distance: 100vh base + 85vh per additional card const containerHeightVh = 100 + (items.length - 1) * 85; return ( @@ -176,7 +208,7 @@ export function CinematicHorizontalScrollSection({ }`} /> - {/* Left Side Arrow Button (Always visible on left side) */} + {/* Left Side Arrow Button */}
- {/* Right Side Arrow Button (Always visible on right side) */} + {/* Right Side Arrow Button */}