feat: seamless sticky showcase scroll, tool page hero comparison, and homepage tool stack sliders

This commit is contained in:
2026-11-04 11:35:51 +05:30
parent c8cf583633
commit 3d207c06e0
3 changed files with 373 additions and 615 deletions
@@ -39,280 +39,180 @@ export function CinematicHorizontalScrollSection({
subtitle = 'Browse the flagship tools with native cinematic pan controls.',
items = [],
}: CinematicHorizontalProps) {
const sectionRef = useRef<HTMLElement>(null);
const railRef = useRef<HTMLDivElement>(null);
const activeIndexRef = useRef(0);
const lastWheelTimeRef = useRef(0);
const containerRef = useRef<HTMLElement>(null);
const trackRef = useRef<HTMLDivElement>(null);
const [translateX, setTranslateX] = useState(0);
const [activeIndex, setActiveIndex] = useState(0);
const [canScrollLeft, setCanScrollLeft] = useState(false);
const [canScrollRight, setCanScrollRight] = useState(true);
// Helper to compute snap-center targets for all cards
const getCardPositions = useCallback(() => {
const rail = railRef.current;
if (!rail) return [];
const cards = Array.from(rail.querySelectorAll('article'));
if (!cards.length) return [];
// Synchronize horizontal track position with vertical scroll progress through sticky section
const updateTranslation = useCallback(() => {
const container = containerRef.current;
const track = trackRef.current;
if (!container || !track) return;
const halfView = rail.clientWidth / 2;
const maxScroll = Math.max(0, rail.scrollWidth - rail.clientWidth);
const rect = container.getBoundingClientRect();
const totalScrollable = container.offsetHeight - window.innerHeight;
if (totalScrollable <= 0) return;
return cards.map((c) => {
const center = c.offsetLeft + c.offsetWidth / 2;
return Math.max(0, Math.min(maxScroll, Math.round(center - halfView)));
});
// Progress: 0.0 when section top hits viewport top, 1.0 when bottom unpins
const progress = Math.max(0, Math.min(1, -rect.top / totalScrollable));
const cards = Array.from(track.querySelectorAll('article'));
if (cards.length <= 1) return;
const firstCenter = cards[0].offsetLeft + cards[0].offsetWidth / 2;
const lastCenter = cards[cards.length - 1].offsetLeft + cards[cards.length - 1].offsetWidth / 2;
const maxDistance = lastCenter - firstCenter;
const targetX = progress * maxDistance;
setTranslateX(targetX);
const active = Math.min(
cards.length - 1,
Math.max(0, Math.round(progress * (cards.length - 1)))
);
setActiveIndex(active);
setCanScrollLeft(progress > 0.02);
setCanScrollRight(progress < 0.98);
}, []);
// Update bounds and sync active card index on scroll
const checkScrollBounds = useCallback(() => {
const rail = railRef.current;
if (!rail) return;
const maxScroll = rail.scrollWidth - rail.clientWidth;
const current = rail.scrollLeft;
setCanScrollLeft(current > 8);
setCanScrollRight(current < maxScroll - 8);
// Sync active index with nearest card
const positions = getCardPositions();
if (positions.length > 0) {
let closest = 0;
let minDiff = Infinity;
positions.forEach((pos, idx) => {
const diff = Math.abs(pos - current);
if (diff < minDiff) {
minDiff = diff;
closest = idx;
}
});
activeIndexRef.current = closest;
}
}, [getCardPositions]);
// Update on mount, resize, and scroll
useEffect(() => {
const rail = railRef.current;
if (!rail) return;
checkScrollBounds();
let ticking = false;
const handleScroll = () => {
checkScrollBounds();
if (!ticking) {
requestAnimationFrame(() => {
updateTranslation();
ticking = false;
});
ticking = true;
}
};
rail.addEventListener('scroll', handleScroll, { passive: true });
window.addEventListener('resize', checkScrollBounds);
updateTranslation();
window.addEventListener('scroll', handleScroll, { passive: true });
window.addEventListener('resize', handleScroll);
return () => {
rail.removeEventListener('scroll', handleScroll);
window.removeEventListener('resize', checkScrollBounds);
window.removeEventListener('scroll', handleScroll);
window.removeEventListener('resize', handleScroll);
};
}, [checkScrollBounds, items.length]);
}, [updateTranslation, items.length]);
// Mandatory Horizontal Scroll Lock:
// Visitor cannot scroll down past this section until the horizontal scroll is completely finished.
useEffect(() => {
const rail = railRef.current;
const section = sectionRef.current;
if (!rail || !section) return;
const WHEEL_COOLDOWN = 450; // Smooth glide cooldown between cards
const handleWheel = (e: WheelEvent) => {
// Allow native 2-finger horizontal trackpad gestures
if (Math.abs(e.deltaX) >= Math.abs(e.deltaY)) {
return;
}
// Ignore micro-jitters
if (Math.abs(e.deltaY) < 8) {
return;
}
const sectionRect = section.getBoundingClientRect();
const railRect = rail.getBoundingClientRect();
const vh = window.innerHeight;
// If the showcase section is completely outside the viewport, do nothing
if (sectionRect.bottom < 0 || sectionRect.top > vh) {
return;
}
const railCenter = railRect.top + railRect.height / 2;
const isDown = e.deltaY > 0;
const isUp = e.deltaY < 0;
const currentIndex = activeIndexRef.current;
const positions = getCardPositions();
if (positions.length <= 1) return;
const lastIndex = positions.length - 1;
// 1. Approaching from above: allow normal page scroll until cards align in the middle of the screen
if (currentIndex === 0 && isDown && railCenter > vh * 0.65) {
return;
}
// 2. Approaching from below: allow normal page scroll up until cards align in the middle of the screen
if (currentIndex === lastIndex && isUp && railCenter < vh * 0.35) {
return;
}
const now = Date.now();
// 3. Mandatory completion release & momentum absorption:
// At last card scrolling down:
if (isDown && currentIndex >= lastIndex) {
// If we just glided to the last card, absorb residual wheel burst so visitor doesn't skip seeing it
if (now - lastWheelTimeRef.current < WHEEL_COOLDOWN + 150) {
e.preventDefault();
return;
}
// Horizontal scroll is complete! Release lock and allow visitor to scroll down the page
return;
}
// At first card scrolling up:
if (isUp && currentIndex <= 0) {
// If we just glided to the first card, absorb residual wheel burst
if (now - lastWheelTimeRef.current < WHEEL_COOLDOWN + 150) {
e.preventDefault();
return;
}
// At first card scrolling up -> release lock and allow visitor to scroll up the page
return;
}
// 4. In all other cases while showcase is aligned in middle and horizontal cards are incomplete:
// LOCK VERTICAL PAGE SCROLL (Visitor CANNOT scroll down past the section until horizontal scroll is finished)
e.preventDefault();
// Absorb rapid wheel bursts during active glide transition
if (now - lastWheelTimeRef.current < WHEEL_COOLDOWN) {
return;
}
lastWheelTimeRef.current = now;
// Glide smoothly to next or previous card
if (isDown && currentIndex < lastIndex) {
const nextIndex = currentIndex + 1;
activeIndexRef.current = nextIndex;
rail.scrollTo({
left: positions[nextIndex],
behavior: 'smooth',
});
} else if (isUp && currentIndex > 0) {
const prevIndex = currentIndex - 1;
activeIndexRef.current = prevIndex;
rail.scrollTo({
left: positions[prevIndex],
behavior: 'smooth',
});
}
};
window.addEventListener('wheel', handleWheel, { passive: false });
return () => {
window.removeEventListener('wheel', handleWheel);
};
}, [getCardPositions]);
// Slide precisely between cards using side arrows
// Slide between cards using side arrows
const scrollDirection = (direction: 'left' | 'right') => {
const rail = railRef.current;
if (!rail) return;
const container = containerRef.current;
if (!container) return;
const totalScrollable = container.offsetHeight - window.innerHeight;
if (totalScrollable <= 0) return;
const positions = getCardPositions();
if (positions.length <= 1) return;
const cardsCount = items.length;
if (cardsCount <= 1) return;
const current = rail.scrollLeft;
let targetIndex = activeIndexRef.current;
const rect = container.getBoundingClientRect();
const containerTopInDoc = window.scrollY + rect.top;
const currentProgress = Math.max(0, Math.min(1, -rect.top / totalScrollable));
const currentCardIndex = Math.min(
cardsCount - 1,
Math.max(0, Math.round(currentProgress * (cardsCount - 1)))
);
let targetIndex = currentCardIndex;
if (direction === 'right') {
const nextIdx = positions.findIndex((pos) => pos > current + 15);
targetIndex = nextIdx !== -1 ? nextIdx : positions.length - 1;
} else {
let prevIdx = -1;
for (let i = positions.length - 1; i >= 0; i--) {
if (positions[i] < current - 15) {
prevIdx = i;
break;
}
}
targetIndex = prevIdx !== -1 ? prevIdx : 0;
targetIndex = Math.min(cardsCount - 1, currentCardIndex + 1);
} else if (direction === 'left') {
targetIndex = Math.max(0, currentCardIndex - 1);
}
activeIndexRef.current = targetIndex;
rail.scrollTo({
left: positions[targetIndex],
const targetProgress = targetIndex / (cardsCount - 1);
const targetScrollY = Math.round(containerTopInDoc + targetProgress * totalScrollable);
window.scrollTo({
top: targetScrollY,
behavior: 'smooth',
});
};
if (!items.length) return null;
// Vertical scroll distance: 100vh base + 85vh per additional card
const containerHeightVh = 100 + (items.length - 1) * 85;
return (
<section
id="flagship-models"
ref={sectionRef}
className="overflow-hidden border-y border-slate-900/[0.08] bg-[#FAF8F5] py-16 sm:py-20 lg:py-24"
ref={containerRef}
className="relative"
style={{ height: `${containerHeightVh}vh` }}
>
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div className="mb-8 flex flex-col gap-4 sm:mb-10 sm:flex-row sm:items-end sm:justify-between">
<div className="max-w-2xl">
<p className="eyebrow">{badge}</p>
<h2 className="mt-3 text-3xl font-display font-bold tracking-tight text-slate-900 sm:text-4xl lg:text-5xl">{title}</h2>
<p className="mt-3 text-sm leading-relaxed text-slate-600 sm:text-base">{subtitle}</p>
<div className="sticky top-0 h-screen flex flex-col justify-center overflow-hidden border-y border-slate-900/[0.08] bg-[#FAF8F5]">
{/* Section Header */}
<div className="mx-auto max-w-7xl w-full px-4 sm:px-6 lg:px-8 mb-4 sm:mb-6 shrink-0">
<div className="flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">
<div className="max-w-2xl">
<p className="eyebrow">{badge}</p>
<h2 className="mt-1 text-2xl font-display font-bold tracking-tight text-slate-900 sm:text-3xl lg:text-4xl">{title}</h2>
<p className="mt-1 text-xs text-slate-600 sm:text-sm">{subtitle}</p>
</div>
<p className="hidden text-xs font-medium text-slate-500 sm:block">Scroll down to explore models</p>
</div>
<p className="hidden text-xs font-medium text-slate-500 sm:block">Scroll cards vertically, swipe, or use side arrows</p>
</div>
</div>
<div className="relative group/showcase">
{/* Soft edge fades for polished visual boundary */}
<div
aria-hidden="true"
className={`pointer-events-none absolute left-0 top-0 bottom-0 w-12 sm:w-20 bg-gradient-to-r from-[#FAF8F5] to-transparent z-10 transition-opacity duration-300 ${
canScrollLeft ? 'opacity-100' : 'opacity-0'
}`}
/>
<div
aria-hidden="true"
className={`pointer-events-none absolute right-0 top-0 bottom-0 w-12 sm:w-20 bg-gradient-to-l from-[#FAF8F5] to-transparent z-10 transition-opacity duration-300 ${
canScrollRight ? 'opacity-100' : 'opacity-0'
}`}
/>
{/* Left Side Arrow Button (Always visible on the left side) */}
<button
type="button"
onClick={() => scrollDirection('left')}
disabled={!canScrollLeft}
aria-label="Previous flagship model"
className={`absolute left-3 sm:left-6 lg:left-8 top-1/2 -translate-y-1/2 z-30 grid h-12 w-12 sm:h-14 sm:w-14 place-items-center rounded-full border border-slate-900/15 bg-white/95 text-slate-800 shadow-cream-md backdrop-blur-md transition-all duration-300 hover:scale-105 hover:bg-white hover:text-blue-600 hover:border-blue-400 hover:shadow-cream-lg active:scale-95 disabled:opacity-35 disabled:cursor-not-allowed disabled:hover:scale-100 disabled:hover:bg-white/95 disabled:hover:text-slate-400 disabled:hover:border-slate-900/15 disabled:shadow-none focus:outline-none focus:ring-2 focus:ring-blue-600`}
>
<ChevronLeft className="h-6 w-6 stroke-[2.5]" />
</button>
{/* Horizontal Rail */}
<div
ref={railRef}
className="cinematic-rail flex snap-x snap-proximity gap-5 overflow-x-auto px-4 pb-5 sm:px-6 lg:px-[max(2rem,calc((100vw-80rem)/2))]"
>
{items.map((item) => (
<ShowcaseCard key={item.id} item={item} />
))}
</div>
{/* Right Side Arrow Button (Always visible on the right side) */}
<button
type="button"
onClick={() => scrollDirection('right')}
disabled={!canScrollRight}
aria-label="Next flagship model"
className={`absolute right-3 sm:right-6 lg:right-8 top-1/2 -translate-y-1/2 z-30 grid h-12 w-12 sm:h-14 sm:w-14 place-items-center rounded-full border border-slate-900/15 bg-white/95 text-slate-800 shadow-cream-md backdrop-blur-md transition-all duration-300 hover:scale-105 hover:bg-white hover:text-blue-600 hover:border-blue-400 hover:shadow-cream-lg active:scale-95 disabled:opacity-35 disabled:cursor-not-allowed disabled:hover:scale-100 disabled:hover:bg-white/95 disabled:hover:text-slate-400 disabled:hover:border-slate-900/15 disabled:shadow-none focus:outline-none focus:ring-2 focus:ring-blue-600`}
>
<ChevronRight className="h-6 w-6 stroke-[2.5]" />
</button>
{/* Carousel Viewport with Pinned Rail & Floating Side Arrows */}
<div className="relative group/showcase w-full overflow-hidden">
{/* Soft edge fades for polished boundary */}
<div
aria-hidden="true"
className={`pointer-events-none absolute left-0 top-0 bottom-0 w-12 sm:w-24 bg-gradient-to-r from-[#FAF8F5] to-transparent z-10 transition-opacity duration-300 ${
canScrollLeft ? 'opacity-100' : 'opacity-0'
}`}
/>
<div
aria-hidden="true"
className={`pointer-events-none absolute right-0 top-0 bottom-0 w-12 sm:w-24 bg-gradient-to-l from-[#FAF8F5] to-transparent z-10 transition-opacity duration-300 ${
canScrollRight ? 'opacity-100' : 'opacity-0'
}`}
/>
{/* Left Side Arrow Button (Always visible on left side) */}
<button
type="button"
onClick={() => scrollDirection('left')}
disabled={!canScrollLeft}
aria-label="Previous flagship model"
className={`absolute left-3 sm:left-6 lg:left-8 top-1/2 -translate-y-1/2 z-30 grid h-12 w-12 sm:h-14 sm:w-14 place-items-center rounded-full border border-slate-900/15 bg-white/95 text-slate-800 shadow-cream-md backdrop-blur-md transition-all duration-300 hover:scale-105 hover:bg-white hover:text-blue-600 hover:border-blue-400 hover:shadow-cream-lg active:scale-95 disabled:opacity-35 disabled:cursor-not-allowed disabled:hover:scale-100 disabled:hover:bg-white/95 disabled:hover:text-slate-400 disabled:hover:border-slate-900/15 disabled:shadow-none focus:outline-none focus:ring-2 focus:ring-blue-600`}
>
<ChevronLeft className="h-6 w-6 stroke-[2.5]" />
</button>
{/* Horizontal Track */}
<div
ref={trackRef}
className="cinematic-rail flex gap-6 will-change-transform"
style={{
paddingLeft: 'calc((100vw - min(780px, 88vw)) / 2)',
paddingRight: 'calc((100vw - min(780px, 88vw)) / 2)',
transform: `translate3d(-${translateX}px, 0, 0)`,
}}
>
{items.map((item) => (
<ShowcaseCard key={item.id} item={item} />
))}
</div>
{/* Right Side Arrow Button (Always visible on right side) */}
<button
type="button"
onClick={() => scrollDirection('right')}
disabled={!canScrollRight}
aria-label="Next flagship model"
className={`absolute right-3 sm:right-6 lg:right-8 top-1/2 -translate-y-1/2 z-30 grid h-12 w-12 sm:h-14 sm:w-14 place-items-center rounded-full border border-slate-900/15 bg-white/95 text-slate-800 shadow-cream-md backdrop-blur-md transition-all duration-300 hover:scale-105 hover:bg-white hover:text-blue-600 hover:border-blue-400 hover:shadow-cream-lg active:scale-95 disabled:opacity-35 disabled:cursor-not-allowed disabled:hover:scale-100 disabled:hover:bg-white/95 disabled:hover:text-slate-400 disabled:hover:border-slate-900/15 disabled:shadow-none focus:outline-none focus:ring-2 focus:ring-blue-600`}
>
<ChevronRight className="h-6 w-6 stroke-[2.5]" />
</button>
</div>
</div>
</section>
);
@@ -322,9 +222,9 @@ function ShowcaseCard({ item }: { item: ShowcaseItem }) {
const comparison = item.variant !== 'banner' && item.beforeUrl && item.afterUrl;
return (
<article className="w-[88vw] shrink-0 snap-center overflow-hidden rounded-3xl border border-slate-900/[0.09] bg-white shadow-cream-md sm:w-[680px] lg:w-[780px]">
<article className="w-[88vw] shrink-0 overflow-hidden rounded-3xl border border-slate-900/[0.09] bg-white shadow-cream-md sm:w-[680px] lg:w-[780px]">
<div className="grid lg:grid-cols-[1.1fr_.9fr]">
<div className="min-h-[280px] bg-slate-100">
<div className="min-h-[260px] sm:min-h-[290px] bg-slate-100">
{comparison ? (
<DeferredComparison
beforeUrl={item.beforeUrl!}
@@ -334,7 +234,7 @@ function ShowcaseCard({ item }: { item: ShowcaseItem }) {
aspectRatio="aspect-[4/3] lg:aspect-auto lg:h-full"
/>
) : (
<div className="relative h-full min-h-[280px] overflow-hidden bg-slate-950">
<div className="relative h-full min-h-[260px] sm:min-h-[290px] overflow-hidden bg-slate-950">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={item.bannerImage || item.beforeUrl || ''}
@@ -351,17 +251,17 @@ function ShowcaseCard({ item }: { item: ShowcaseItem }) {
)}
</div>
<div className="flex flex-col p-6 sm:p-7">
<div className="flex flex-col p-5 sm:p-6 lg:p-7">
<div className="flex items-center justify-between gap-3">
<span className="text-xs font-bold tracking-[0.16em] text-blue-700">{item.index}</span>
<span className="rounded-full border border-emerald-200 bg-emerald-50 px-2.5 py-1 text-[10px] font-semibold text-emerald-800">
{item.latency}
</span>
</div>
<p className="mt-5 text-xs font-semibold uppercase tracking-[0.12em] text-slate-500">{item.category}</p>
<h3 className="mt-2 text-2xl font-display font-bold leading-tight tracking-tight text-slate-900">{item.title}</h3>
<p className="mt-3 text-sm leading-relaxed text-slate-600">{item.description}</p>
<ul className="mt-5 space-y-2.5 text-sm text-slate-700">
<p className="mt-4 text-xs font-semibold uppercase tracking-[0.12em] text-slate-500">{item.category}</p>
<h3 className="mt-1.5 text-xl font-display font-bold leading-tight tracking-tight text-slate-900 sm:text-2xl">{item.title}</h3>
<p className="mt-2 text-xs leading-relaxed text-slate-600 sm:text-sm">{item.description}</p>
<ul className="mt-4 space-y-2 text-xs sm:text-sm text-slate-700">
{item.specs.slice(0, 3).map((spec) => (
<li key={spec} className="flex gap-2">
<Check className="mt-0.5 h-4 w-4 shrink-0 text-blue-700" />
@@ -369,11 +269,11 @@ function ShowcaseCard({ item }: { item: ShowcaseItem }) {
</li>
))}
</ul>
<div className="mt-7 flex flex-wrap gap-3">
<Link href={`/tools/${item.toolSlug}`} className="button-primary">
<div className="mt-5 flex flex-wrap gap-3">
<Link href={`/tools/${item.toolSlug}`} className="button-primary text-xs sm:text-sm py-2 px-4 sm:py-2.5 sm:px-5">
Try online <ArrowRight className="h-4 w-4" />
</Link>
<Link href={`/apps/${item.appSlug}`} className="button-secondary">
<Link href={`/apps/${item.appSlug}`} className="button-secondary text-xs sm:text-sm py-2 px-4 sm:py-2.5 sm:px-5">
<Smartphone className="h-4 w-4" /> App
</Link>
</div>