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 React, { useRef, useState, useEffect } from 'react';
import Link from 'next/link'; 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'; import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison';
interface ShowcaseCard { interface ShowcaseCard {
@@ -76,57 +76,76 @@ const showcaseCards: ShowcaseCard[] = [
export function CinematicHorizontalScrollSection() { export function CinematicHorizontalScrollSection() {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const trackRef = 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(() => { useEffect(() => {
let rafId: number; let rafId: number;
let targetX = 0;
let currentX = 0;
let isTracking = true;
const handleScroll = () => { // High-precision lerp animation loop (eliminates CSS transition conflicts for butter-smooth 120 FPS glide)
if (!containerRef.current || !trackRef.current) return; const updateMotion = () => {
const rect = containerRef.current.getBoundingClientRect(); if (!isTracking) return;
const totalScrollable = containerRef.current.offsetHeight - window.innerHeight;
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 if (totalScrollable > 0) {
const progress = Math.min(Math.max(-rect.top / totalScrollable, 0), 1); const rawProgress = Math.min(Math.max(-rect.top / totalScrollable, 0), 1);
setScrollProgress(progress); const maxTranslate = trackRef.current.scrollWidth - window.innerWidth;
// Translate track horizontally if (maxTranslate > 0) {
const maxTranslate = trackRef.current.scrollWidth - window.innerWidth; targetX = rawProgress * maxTranslate;
if (maxTranslate > 0) { }
trackRef.current.style.transform = `translate3d(-${progress * maxTranslate}px, 0, 0)`;
// 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 = () => { rafId = requestAnimationFrame(updateMotion);
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);
return () => { return () => {
clearInterval(bindLenisInterval); isTracking = false;
window.removeEventListener('scroll', onScroll);
window.removeEventListener('touchmove', onScroll);
window.removeEventListener('resize', onScroll);
if (boundLenis && typeof boundLenis.off === 'function') {
boundLenis.off('scroll', onScroll);
}
cancelAnimationFrame(rafId); cancelAnimationFrame(rafId);
}; };
}, []); }, []);
@@ -135,18 +154,29 @@ export function CinematicHorizontalScrollSection() {
<section <section
id="flagship-models" id="flagship-models"
ref={containerRef} 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 */} {/* 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"> <div className="sticky top-0 h-screen w-full overflow-hidden flex flex-col justify-between py-10 sm:py-14 select-none">
{/* Background Subtle Ambient Gradients */} {/* Massive 3D Kinetic Background Typography Ribbon (Parallax Drift) */}
<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
<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" /> 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 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="preserve-3d">
<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="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" /> <Sparkles className="w-3.5 h-3.5 text-blue-600" />
<span>HORIZONTAL 3D CINEMATIC ARCHIVE</span> <span>HORIZONTAL 3D CINEMATIC ARCHIVE</span>
</div> </div>
@@ -156,32 +186,32 @@ export function CinematicHorizontalScrollSection() {
</div> </div>
<div className="flex items-center gap-3"> <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 SCROLL DOWN TO PAN HORIZONTALLY
</span> </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 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> </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 className="relative w-full my-auto overflow-visible py-4">
<div <div
ref={trackRef} 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 <div
key={card.id} 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" 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"
style={{
transform: `perspective(1200px) rotateY(${(scrollProgress - idx / (showcaseCards.length - 1)) * -12}deg)`,
}}
> >
{/* Card Top Metadata Bar */} {/* Card Top Metadata Bar (translateZ 30px) */}
<div className="flex items-center justify-between pb-4 border-b border-slate-900/[0.06] mb-5"> <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"> <div className="flex items-center gap-3">
<span className="font-mono text-xs font-black text-blue-700 tracking-wider"> <span className="font-mono text-xs font-black text-blue-700 tracking-wider">
{card.index} {card.index}
@@ -209,17 +239,29 @@ export function CinematicHorizontalScrollSection() {
/> />
</div> </div>
{/* Card Editorial Info */} {/* Card 3D Stereoscopic Typography Stack */}
<div className="space-y-3"> <div className="space-y-3 preserve-3d">
<h3 className="text-xl sm:text-2xl font-display font-bold text-slate-900 tracking-tight"> {/* 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} {card.title}
</h3> </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} {card.description}
</p> </p>
{/* Specs Chips */} {/* Specs Chips at translateZ 35px */}
<div className="flex flex-wrap gap-2 pt-2"> <div
className="flex flex-wrap gap-2 pt-2 preserve-3d"
style={{ transform: 'translateZ(35px)' }}
>
{card.specs.map((spec, i) => ( {card.specs.map((spec, i) => (
<span <span
key={i} key={i}
@@ -230,8 +272,11 @@ export function CinematicHorizontalScrollSection() {
))} ))}
</div> </div>
{/* Actions */} {/* Actions at translateZ 50px */}
<div className="pt-4 flex flex-wrap items-center justify-between gap-3 border-t border-slate-900/[0.06]"> <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 <Link
href={`/tools/${card.toolSlug}`} href={`/tools/${card.toolSlug}`}
className="inline-flex items-center gap-2 text-xs font-bold text-blue-700 hover:text-blue-900 group/link" 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="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="w-full bg-slate-200/80 h-1.5 rounded-full overflow-hidden shadow-inner">
<div <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" ref={progressBarRef}
style={{ width: `${Math.max(scrollProgress * 100, 3)}%` }} 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>
</div> </div>
+19 -13
View File
@@ -7,6 +7,7 @@ import { resolveLocalised, ToolItem, AppItem, VariantSpec } from '@/types';
import { TryItWidget } from './TryItWidget'; import { TryItWidget } from './TryItWidget';
import { TiltCard } from '@/components/ui/TiltCard'; import { TiltCard } from '@/components/ui/TiltCard';
import { Hero3DCanvas } from '@/components/3d/Hero3DCanvas'; import { Hero3DCanvas } from '@/components/3d/Hero3DCanvas';
import { Kinetic3DText } from '@/components/ui/Kinetic3DText';
interface HeroSectionProps { interface HeroSectionProps {
title?: any; 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="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"> <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 */} {/* 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"> <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" /> <Hero3DCanvas className="w-full h-full" />
@@ -61,23 +73,17 @@ export function HeroSection({
<span>{resolvedBadge}</span> <span>{resolvedBadge}</span>
</div> </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> <span>VOL. 26 // NEURAL STUDIO</span>
</div> </div>
</div> </div>
{/* Main Headline with Editorial Kerning and Fluid Scale */} {/* 3D Kinetic Interactive Typography */}
<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"> <Kinetic3DText
Transform Photos with <br className="hidden sm:inline" /> primaryText="Transform Photos with"
<span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-700 via-indigo-600 to-amber-600"> highlightText="Next-Gen Neural AI"
Next-Gen Neural AI subtitle={resolvedSubtitle}
</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>
</div> </div>
{/* Embedded Interactive Free Try-It Widget wrapped with 3D Tilt Card */} {/* Embedded Interactive Free Try-It Widget wrapped with 3D Tilt Card */}
+108
View File
@@ -0,0 +1,108 @@
'use client';
import React, { useState, useRef, useEffect } from 'react';
interface Kinetic3DTextProps {
primaryText: string;
highlightText?: string;
subtitle?: string;
className?: string;
}
export function Kinetic3DText({
primaryText,
highlightText,
subtitle,
className = '',
}: Kinetic3DTextProps) {
const [tilt, setTilt] = useState({ rx: 0, ry: 0, active: false });
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
let rafId: number;
let targetRx = 0;
let targetRy = 0;
let currentRx = 0;
let currentRy = 0;
const handleMouseMove = (e: MouseEvent) => {
if (!containerRef.current) return;
const rect = containerRef.current.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
// Normalized coordinates -1 to +1
const nx = (e.clientX - centerX) / (window.innerWidth * 0.5);
const ny = (e.clientY - centerY) / (window.innerHeight * 0.5);
targetRy = Math.max(Math.min(nx * 10, 12), -12);
targetRx = Math.max(Math.min(-ny * 8, 10), -10);
};
const updateLoop = () => {
// Smooth inertial lerp
currentRx += (targetRx - currentRx) * 0.1;
currentRy += (targetRy - currentRy) * 0.1;
if (containerRef.current) {
containerRef.current.style.transform = `rotateX(${currentRx.toFixed(2)}deg) rotateY(${currentRy.toFixed(2)}deg)`;
}
rafId = requestAnimationFrame(updateLoop);
};
window.addEventListener('mousemove', handleMouseMove, { passive: true });
rafId = requestAnimationFrame(updateLoop);
return () => {
window.removeEventListener('mousemove', handleMouseMove);
cancelAnimationFrame(rafId);
};
}, []);
return (
<div className={`relative perspective-1000 select-none ${className}`}>
{/* 3D Stereoscopic Kinetic Text Stage */}
<div
ref={containerRef}
className="preserve-3d transition-transform duration-75 ease-out will-change-transform"
>
{/* Layer 1: Ambient 3D Text Holographic Depth Shadow */}
<div
className="absolute inset-0 select-none pointer-events-none opacity-20 blur-md transform translate-z-[-20px] scale-[1.03]"
aria-hidden="true"
>
<span className="text-4xl sm:text-5xl lg:text-6xl xl:text-7xl font-display font-black text-blue-700 leading-[1.08] tracking-tight block">
{primaryText} <br className="hidden sm:inline" />
{highlightText}
</span>
</div>
{/* Layer 2: Main Floating 3D Headline */}
<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] relative z-10 preserve-3d"
style={{ transform: 'translateZ(35px)' }}
>
<span>{primaryText}</span> <br className="hidden sm:inline" />
{highlightText && (
<span className="relative inline-block mt-1 sm:mt-0 preserve-3d">
<span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-700 via-indigo-600 to-amber-600 drop-shadow-[0_4px_12px_rgba(37,99,235,0.25)]">
{highlightText}
</span>
</span>
)}
</h1>
{/* Layer 3: Elevated Subtitle */}
{subtitle && (
<p
className="mt-6 text-base sm:text-lg lg:text-xl text-slate-600 leading-relaxed max-w-2xl mx-auto font-normal preserve-3d"
style={{ transform: 'translateZ(20px)' }}
>
{subtitle}
</p>
)}
</div>
</div>
);
}