Files
0pt/components/sections/editorial-section.tsx
T
2026-06-24 14:47:12 +00:00

105 lines
3.3 KiB
TypeScript

"use client";
import { useRef, useState, useEffect, useCallback } from "react";
const specs = [
{ label: "Surface Area", value: "180m²" },
{ label: "Energy Use", value: "15 kWh/m²" },
{ label: "Solar Panels", value: "40 m²" },
{ label: "Carbon Balance", value: "-20%" },
];
export function EditorialSection() {
const videoRef = useRef<HTMLDivElement>(null);
const [scrollProgress, setScrollProgress] = useState(0);
const rafRef = useRef<number | null>(null);
const updateParallax = useCallback(() => {
if (!videoRef.current) return;
const rect = videoRef.current.getBoundingClientRect();
const windowHeight = window.innerHeight;
// Calculate when video enters and exits viewport
const videoTop = rect.top;
const videoBottom = rect.bottom;
// Progress from 0 (entering viewport) to 1 (exiting viewport)
if (videoBottom > 0 && videoTop < windowHeight) {
const progress = 1 - (videoTop + rect.height / 2) / (windowHeight + rect.height);
setScrollProgress(Math.max(0, Math.min(1, progress)));
}
}, []);
useEffect(() => {
const handleScroll = () => {
if (rafRef.current) {
cancelAnimationFrame(rafRef.current);
}
rafRef.current = requestAnimationFrame(updateParallax);
};
window.addEventListener("scroll", handleScroll, { passive: true });
updateParallax();
return () => {
window.removeEventListener("scroll", handleScroll);
if (rafRef.current) {
cancelAnimationFrame(rafRef.current);
}
};
}, [updateParallax]);
// Parallax effect: video moves up as you scroll down
const parallaxY = (scrollProgress - 0.5) * 30; // -15px to +15px range
return (
<section className="bg-background">
{/* Newsletter Banner */}
{/* Decorative Icons */}
<div className="flex items-center justify-center gap-6 pb-20">
</div>
{/* Full-width Video with Parallax */}
<div ref={videoRef} className="relative aspect-[16/9] w-full md:aspect-[21/9] overflow-hidden">
<video
autoPlay
loop
muted
playsInline
className="absolute inset-0 h-full w-full object-cover"
style={{
transform: `scale(1.15) translate3d(0, ${parallaxY}px, 0) translateZ(0)`,
WebkitTransform: `scale(1.15) translate3d(0, ${parallaxY}px, 0) translateZ(0)`,
backfaceVisibility: 'hidden',
WebkitBackfaceVisibility: 'hidden',
willChange: 'transform',
}}
src="https://hebbkx1anhila5yf.public.blob.vercel-storage.com/27eb7fb4-0105-4010-ac9e-0ac977a31b05_1-FZ89nvBAAsR3caRJbhYv7T2mjBofth.mp4"
/>
</div>
{/* Specs Grid */}
<div className="grid grid-cols-2 border-t border-border md:grid-cols-4">
{specs.map((spec) => (
<div
key={spec.label}
className="border-b border-r border-border p-8 text-center last:border-r-0 md:border-b-0"
>
<p className="mb-2 text-xs uppercase tracking-widest text-muted-foreground">
{spec.label}
</p>
<p className="font-medium text-foreground text-5xl">
{spec.value}
</p>
</div>
))}
</div>
</section>
);
}