← back to Watches
src/components/ParallaxSection.jsx
77 lines
import React, { useEffect, useState, useRef } from 'react';
import { motion, useScroll, useTransform } from 'framer-motion';
/**
* Parallax Section Component
* Features: Multi-layer parallax scrolling, cinematic effects
*/
const ParallaxSection = ({ title, subtitle, children, image, darkOverlay = true }) => {
const ref = useRef(null);
const { scrollYProgress } = useScroll({
target: ref,
offset: ['start end', 'end start'],
});
const y = useTransform(scrollYProgress, [0, 1], ['0%', '30%']);
const opacity = useTransform(scrollYProgress, [0, 0.5, 1], [0.3, 1, 0.3]);
const scale = useTransform(scrollYProgress, [0, 0.5, 1], [0.95, 1, 0.95]);
return (
<div ref={ref} className="relative min-h-screen flex items-center justify-center overflow-hidden">
{/* Parallax background */}
<motion.div
className="absolute inset-0 z-0"
style={{ y }}
>
{image && (
<div
className="absolute inset-0 bg-cover bg-center"
style={{ backgroundImage: `url(${image})` }}
/>
)}
{darkOverlay && (
<div className="absolute inset-0 bg-gradient-to-b from-gray-900/90 via-gray-900/70 to-gray-900/90" />
)}
</motion.div>
{/* Content */}
<motion.div
className="relative z-10 max-w-6xl mx-auto px-4 text-center"
style={{ opacity, scale }}
>
{title && (
<motion.h2
className="text-5xl md:text-7xl font-display font-bold mb-6 text-reveal"
initial={{ opacity: 0, y: 30 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true }}
transition={{ duration: 0.8 }}
>
<span className="text-gold">{title}</span>
</motion.h2>
)}
{subtitle && (
<motion.p
className="text-xl md:text-2xl font-luxury text-gray-300 mb-12"
initial={{ opacity: 0, y: 20 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true }}
transition={{ duration: 0.8, delay: 0.2 }}
>
{subtitle}
</motion.p>
)}
{children}
</motion.div>
{/* Decorative elements */}
<div className="absolute top-0 left-0 w-full h-px bg-gradient-to-r from-transparent via-gold to-transparent opacity-30" />
<div className="absolute bottom-0 left-0 w-full h-px bg-gradient-to-r from-transparent via-gold to-transparent opacity-30" />
</div>
);
};
export default ParallaxSection;