feat(ui): smooth horizontal scroll with script lerp and add interactive 3d kinetic typography

This commit is contained in:
2026-11-03 16:49:56 +05:30
parent f4f22be762
commit c764ffca14
3 changed files with 243 additions and 83 deletions
@@ -2,7 +2,7 @@
import React, { useRef, useState, useEffect } from 'react';
import Link from 'next/link';
import { Sparkles, ArrowRight, Smartphone, Zap, Shield, Layers } from 'lucide-react';
import { Sparkles, ArrowRight, Smartphone } from 'lucide-react';
import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison';
interface ShowcaseCard {
@@ -76,57 +76,76 @@ const showcaseCards: ShowcaseCard[] = [
export function CinematicHorizontalScrollSection() {
const containerRef = useRef<HTMLDivElement>(null);
const trackRef = useRef<HTMLDivElement>(null);
const [scrollProgress, setScrollProgress] = useState(0);
const bgTextRef = useRef<HTMLDivElement>(null);
const progressBarRef = useRef<HTMLDivElement>(null);
const progressTextRef = useRef<HTMLSpanElement>(null);
useEffect(() => {
let rafId: number;
let targetX = 0;
let currentX = 0;
let isTracking = true;
const handleScroll = () => {
if (!containerRef.current || !trackRef.current) return;
const rect = containerRef.current.getBoundingClientRect();
const totalScrollable = containerRef.current.offsetHeight - window.innerHeight;
// High-precision lerp animation loop (eliminates CSS transition conflicts for butter-smooth 120 FPS glide)
const updateMotion = () => {
if (!isTracking) return;
if (totalScrollable <= 0) return;
if (containerRef.current && trackRef.current) {
const rect = containerRef.current.getBoundingClientRect();
const totalScrollable = containerRef.current.offsetHeight - window.innerHeight;
// Calculate progress 0 to 1
const progress = Math.min(Math.max(-rect.top / totalScrollable, 0), 1);
setScrollProgress(progress);
if (totalScrollable > 0) {
const rawProgress = Math.min(Math.max(-rect.top / totalScrollable, 0), 1);
const maxTranslate = trackRef.current.scrollWidth - window.innerWidth;
// Translate track horizontally
const maxTranslate = trackRef.current.scrollWidth - window.innerWidth;
if (maxTranslate > 0) {
trackRef.current.style.transform = `translate3d(-${progress * maxTranslate}px, 0, 0)`;
if (maxTranslate > 0) {
targetX = rawProgress * maxTranslate;
}
// Smooth exponential damping (lerp factor 0.085)
currentX += (targetX - currentX) * 0.085;
// Apply 100% GPU compositor transform without CSS transition lag
trackRef.current.style.transform = `translate3d(-${currentX.toFixed(2)}px, 0, 0)`;
// Parallax 3D background typography ribbon drifting in opposite perspective
if (bgTextRef.current) {
bgTextRef.current.style.transform = `translate3d(-${(currentX * 0.4).toFixed(2)}px, 0, 0) rotateX(10deg)`;
}
// Update Progress Indicator directly in DOM (zero React re-renders)
const liveProgress = Math.min(Math.max(currentX / (maxTranslate || 1), 0), 1);
if (progressBarRef.current) {
progressBarRef.current.style.width = `${Math.max(liveProgress * 100, 4).toFixed(1)}%`;
}
if (progressTextRef.current) {
progressTextRef.current.textContent = `PROGRESS ${Math.round(liveProgress * 100)}%`;
}
// 3D Perspective rotational offset on individual cards
const cards = trackRef.current.children;
const screenCenter = window.innerWidth / 2;
for (let i = 0; i < cards.length; i++) {
const card = cards[i] as HTMLElement;
const cardRect = card.getBoundingClientRect();
const cardCenter = cardRect.left + cardRect.width / 2;
const dist = (cardCenter - screenCenter) / (window.innerWidth * 0.6);
const rotY = Math.max(Math.min(dist * -8, 14), -14);
const scale = Math.max(1 - Math.abs(dist) * 0.04, 0.94);
card.style.transform = `perspective(1200px) rotateY(${rotY.toFixed(2)}deg) scale3d(${scale.toFixed(3)}, ${scale.toFixed(3)}, 1)`;
}
}
}
rafId = requestAnimationFrame(updateMotion);
};
const onScroll = () => {
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(handleScroll);
};
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('touchmove', onScroll, { passive: true });
window.addEventListener('resize', onScroll, { passive: true });
handleScroll();
let boundLenis: any = null;
const bindLenisInterval = setInterval(() => {
const lenis = (window as any).lenis;
if (lenis && typeof lenis.on === 'function') {
boundLenis = lenis;
lenis.on('scroll', onScroll);
clearInterval(bindLenisInterval);
}
}, 50);
rafId = requestAnimationFrame(updateMotion);
return () => {
clearInterval(bindLenisInterval);
window.removeEventListener('scroll', onScroll);
window.removeEventListener('touchmove', onScroll);
window.removeEventListener('resize', onScroll);
if (boundLenis && typeof boundLenis.off === 'function') {
boundLenis.off('scroll', onScroll);
}
isTracking = false;
cancelAnimationFrame(rafId);
};
}, []);
@@ -135,18 +154,29 @@ export function CinematicHorizontalScrollSection() {
<section
id="flagship-models"
ref={containerRef}
className="relative h-[280vh] sm:h-[340vh] bg-[#FAF8F5] border-t border-slate-900/[0.08]"
className="relative h-[290vh] sm:h-[350vh] bg-[#FAF8F5] border-t border-slate-900/[0.08] overflow-visible"
>
{/* Sticky Fullscreen Camera Viewport */}
<div className="sticky top-0 h-screen w-full overflow-hidden flex flex-col justify-between py-12 sm:py-16">
{/* Background Subtle Ambient Gradients */}
<div className="absolute top-1/4 left-1/3 w-[500px] h-[500px] bg-blue-500/[0.03] rounded-full blur-3xl pointer-events-none -z-10" />
<div className="absolute bottom-1/4 right-1/4 w-[450px] h-[450px] bg-amber-500/[0.025] rounded-full blur-3xl pointer-events-none -z-10" />
<div className="sticky top-0 h-screen w-full overflow-hidden flex flex-col justify-between py-10 sm:py-14 select-none">
{/* Massive 3D Kinetic Background Typography Ribbon (Parallax Drift) */}
<div
ref={bgTextRef}
className="absolute top-1/2 -translate-y-1/2 left-0 w-max whitespace-nowrap pointer-events-none -z-10 opacity-30 select-none preserve-3d"
aria-hidden="true"
>
<span className="font-display font-black text-[13vw] uppercase tracking-tighter text-transparent bg-clip-text bg-gradient-to-r from-slate-900/10 via-blue-900/15 to-amber-900/10 block leading-none">
01 ALPHA MATTING // 02 DERMAL RETOUCH // 03 4K SUPER-RES // STUDIO ARCHIVE //
</span>
</div>
{/* Section Top Header & Navigation Telemetry */}
{/* Ambient Subtle Gradients */}
<div className="absolute top-1/4 left-1/3 w-[500px] h-[500px] bg-blue-500/[0.035] rounded-full blur-3xl pointer-events-none -z-10" />
<div className="absolute bottom-1/4 right-1/4 w-[450px] h-[450px] bg-amber-500/[0.03] rounded-full blur-3xl pointer-events-none -z-10" />
{/* Section Top Header & Navigation Telemetry with 3D Depth */}
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 w-full z-10 flex flex-col sm:flex-row sm:items-end justify-between gap-4">
<div>
<div className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full bg-blue-50/80 border border-blue-200/80 text-[11px] font-mono font-semibold text-blue-700 mb-2">
<div className="preserve-3d">
<div className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full bg-blue-50/90 border border-blue-200/80 text-[11px] font-mono font-semibold text-blue-700 mb-2 shadow-sm">
<Sparkles className="w-3.5 h-3.5 text-blue-600" />
<span>HORIZONTAL 3D CINEMATIC ARCHIVE</span>
</div>
@@ -156,32 +186,32 @@ export function CinematicHorizontalScrollSection() {
</div>
<div className="flex items-center gap-3">
<span className="text-xs font-mono font-bold text-slate-500 uppercase tracking-widest">
<span className="text-xs font-mono font-bold text-slate-500 uppercase tracking-widest hidden sm:inline">
SCROLL DOWN TO PAN HORIZONTALLY
</span>
<div className="hidden sm:flex items-center gap-1.5 px-3 py-1 rounded-lg bg-white/70 backdrop-blur-sm border border-slate-900/[0.06] text-xs font-mono font-bold text-slate-700">
<div className="flex items-center gap-1.5 px-3 py-1 rounded-lg bg-white/80 backdrop-blur-sm border border-slate-900/[0.06] text-xs font-mono font-bold text-slate-700 shadow-sm">
<span className="w-2 h-2 rounded-full bg-blue-600 animate-ping inline-block" />
<span>PROGRESS {Math.round(scrollProgress * 100)}%</span>
<span ref={progressTextRef}>PROGRESS 0%</span>
</div>
</div>
</div>
{/* Horizontal Sliding Filmstrip Track */}
{/* Horizontal Sliding Filmstrip Track (Zero CSS transition conflicts, 100% hardware GPU translation) */}
<div className="relative w-full my-auto overflow-visible py-4">
<div
ref={trackRef}
className="flex items-center gap-8 sm:gap-14 px-6 sm:px-12 lg:px-20 w-max will-change-transform preserve-3d transition-transform duration-75 ease-out"
className="flex items-center gap-8 sm:gap-14 px-6 sm:px-12 lg:px-20 w-max will-change-transform preserve-3d"
>
{showcaseCards.map((card, idx) => (
{showcaseCards.map((card) => (
<div
key={card.id}
className="w-[85vw] sm:w-[620px] lg:w-[740px] shrink-0 bg-white/90 backdrop-blur-xl rounded-3xl p-5 sm:p-8 border border-slate-900/[0.08] shadow-cinematic-3d hover:shadow-cinematic-hover transition-all duration-300 preserve-3d group"
style={{
transform: `perspective(1200px) rotateY(${(scrollProgress - idx / (showcaseCards.length - 1)) * -12}deg)`,
}}
className="w-[85vw] sm:w-[620px] lg:w-[740px] shrink-0 bg-white/95 backdrop-blur-xl rounded-3xl p-5 sm:p-8 border border-slate-900/[0.08] shadow-cinematic-3d hover:shadow-cinematic-hover transition-shadow duration-300 preserve-3d group"
>
{/* Card Top Metadata Bar */}
<div className="flex items-center justify-between pb-4 border-b border-slate-900/[0.06] mb-5">
{/* Card Top Metadata Bar (translateZ 30px) */}
<div
className="flex items-center justify-between pb-4 border-b border-slate-900/[0.06] mb-5 preserve-3d"
style={{ transform: 'translateZ(30px)' }}
>
<div className="flex items-center gap-3">
<span className="font-mono text-xs font-black text-blue-700 tracking-wider">
{card.index}
@@ -209,17 +239,29 @@ export function CinematicHorizontalScrollSection() {
/>
</div>
{/* Card Editorial Info */}
<div className="space-y-3">
<h3 className="text-xl sm:text-2xl font-display font-bold text-slate-900 tracking-tight">
{/* Card 3D Stereoscopic Typography Stack */}
<div className="space-y-3 preserve-3d">
{/* Headline at translateZ 45px */}
<h3
className="text-xl sm:text-2xl font-display font-bold text-slate-900 tracking-tight preserve-3d drop-shadow-[0_2px_8px_rgba(15,23,42,0.08)]"
style={{ transform: 'translateZ(45px)' }}
>
{card.title}
</h3>
<p className="text-sm text-slate-600 leading-relaxed font-normal">
{/* Description at translateZ 25px */}
<p
className="text-sm text-slate-600 leading-relaxed font-normal preserve-3d"
style={{ transform: 'translateZ(25px)' }}
>
{card.description}
</p>
{/* Specs Chips */}
<div className="flex flex-wrap gap-2 pt-2">
{/* Specs Chips at translateZ 35px */}
<div
className="flex flex-wrap gap-2 pt-2 preserve-3d"
style={{ transform: 'translateZ(35px)' }}
>
{card.specs.map((spec, i) => (
<span
key={i}
@@ -230,8 +272,11 @@ export function CinematicHorizontalScrollSection() {
))}
</div>
{/* Actions */}
<div className="pt-4 flex flex-wrap items-center justify-between gap-3 border-t border-slate-900/[0.06]">
{/* Actions at translateZ 50px */}
<div
className="pt-4 flex flex-wrap items-center justify-between gap-3 border-t border-slate-900/[0.06] preserve-3d"
style={{ transform: 'translateZ(50px)' }}
>
<Link
href={`/tools/${card.toolSlug}`}
className="inline-flex items-center gap-2 text-xs font-bold text-blue-700 hover:text-blue-900 group/link"
@@ -258,8 +303,9 @@ export function CinematicHorizontalScrollSection() {
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 w-full z-10">
<div className="w-full bg-slate-200/80 h-1.5 rounded-full overflow-hidden shadow-inner">
<div
className="h-full bg-gradient-to-r from-blue-600 via-indigo-600 to-amber-500 rounded-full transition-all duration-100 ease-out"
style={{ width: `${Math.max(scrollProgress * 100, 3)}%` }}
ref={progressBarRef}
className="h-full bg-gradient-to-r from-blue-600 via-indigo-600 to-amber-500 rounded-full will-change-transform"
style={{ width: '4%' }}
/>
</div>
</div>
+19 -13
View File
@@ -7,6 +7,7 @@ import { resolveLocalised, ToolItem, AppItem, VariantSpec } from '@/types';
import { TryItWidget } from './TryItWidget';
import { TiltCard } from '@/components/ui/TiltCard';
import { Hero3DCanvas } from '@/components/3d/Hero3DCanvas';
import { Kinetic3DText } from '@/components/ui/Kinetic3DText';
interface HeroSectionProps {
title?: any;
@@ -43,6 +44,17 @@ export function HeroSection({
<div className="absolute top-0 left-1/2 -translate-x-1/2 w-full max-w-7xl h-[450px] bg-gradient-to-b from-blue-500/[0.04] via-indigo-500/[0.03] to-transparent blur-3xl pointer-events-none -z-10" />
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10">
{/* Subtle Massive 3D Background Typographic Watermark (Enigma Style) */}
<div
className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-max select-none pointer-events-none opacity-[0.04] -z-20 preserve-3d"
style={{ transform: 'perspective(1000px) rotateX(10deg)' }}
aria-hidden="true"
>
<span className="text-[14vw] font-display font-black tracking-tighter text-slate-950 uppercase leading-none block">
CRE INNOVATIONS // NEURAL VISION
</span>
</div>
{/* 3D Ambient Kinetic Prism Floating Behind Header */}
<div className="absolute top-12 left-1/2 -translate-x-1/2 w-[320px] h-[320px] pointer-events-none -z-10 opacity-70 hidden md:block">
<Hero3DCanvas className="w-full h-full" />
@@ -61,23 +73,17 @@ export function HeroSection({
<span>{resolvedBadge}</span>
</div>
)}
<div className="hidden sm:inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-amber-50/80 border border-amber-200/60 text-[11px] font-mono font-bold text-amber-800">
<div className="hidden sm:inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-amber-50/80 border border-amber-200/60 text-[11px] font-mono font-bold text-amber-800 shadow-sm">
<span>VOL. 26 // NEURAL STUDIO</span>
</div>
</div>
{/* Main Headline with Editorial Kerning and Fluid Scale */}
<h1 className="text-4xl sm:text-5xl lg:text-6xl xl:text-7xl font-display font-black text-slate-900 tracking-tight leading-[1.08] max-w-4xl mx-auto">
Transform Photos with <br className="hidden sm:inline" />
<span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-700 via-indigo-600 to-amber-600">
Next-Gen Neural AI
</span>
</h1>
{/* Subtitle with Refined Editorial Measure */}
<p className="text-base sm:text-lg lg:text-xl text-slate-600 leading-relaxed max-w-2xl mx-auto font-normal">
{resolvedSubtitle}
</p>
{/* 3D Kinetic Interactive Typography */}
<Kinetic3DText
primaryText="Transform Photos with"
highlightText="Next-Gen Neural AI"
subtitle={resolvedSubtitle}
/>
</div>
{/* Embedded Interactive Free Try-It Widget wrapped with 3D Tilt Card */}