diff --git a/src/components/LazyVideoHero/LazyVideoHero.tsx b/src/components/LazyVideoHero/LazyVideoHero.tsx new file mode 100644 index 0000000..c6c0045 --- /dev/null +++ b/src/components/LazyVideoHero/LazyVideoHero.tsx @@ -0,0 +1,86 @@ +import { useEffect, useRef, useState } from 'react'; + +interface LazyVideoHeroProps { + children?: React.ReactNode; +} + +export default function LazyVideoHero({ children }: LazyVideoHeroProps) { + const containerRef = useRef(null); + const videoRef = useRef(null); + const [isIntersecting, setIsIntersecting] = useState(true); + + useEffect(() => { + const container = containerRef.current; + if (!container) return; + + const observer = new IntersectionObserver( + ([entry]) => { + setIsIntersecting(entry.isIntersecting); + if (videoRef.current) { + if (entry.isIntersecting) { + videoRef.current.play().catch(() => { + // Ignore autoplay restrictions if browser blocks + }); + } else { + videoRef.current.pause(); + } + } + }, + { + threshold: 0.1, // Pause when 90% of section is out of view + } + ); + + observer.observe(container); + + return () => { + observer.disconnect(); + }; + }, []); + + return ( +
+ {/* ─── Optimized Video Background ────────────────────────────────────────── */} +
+ + + {/* High-Contrast Glassmorphic Overlay Gradient */} +
+
+ + {/* ─── Hero Content ──────────────────────────────────────────────────────── */} +
+ {children} +
+
+ ); +} diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index c4a76fb..ef19375 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -11,6 +11,8 @@ import AnimatedContainer from '@/components/AnimatedContainer/AnimatedContainer' import { FEATURES, CAMPUS_LOCATIONS } from '@/constants'; import * as LucideIcons from 'lucide-react'; +import LazyVideoHero from '@/components/LazyVideoHero/LazyVideoHero'; + export default function Home() { const { scrollY } = useScroll(); const heroOpacity = useTransform(scrollY, [0, 450], [1, 0]); @@ -18,31 +20,13 @@ export default function Home() { return (
- {/* ─── Ultra-Sleek Mesh Background Effect (Lightweight - Zero Video Load) ─── */} -
-
-
-
-
- - {/* ─── Hero Section ─────────────────────────────────────────────────────── */} -
- + {/* ─── Hero Section with IntersectionObserver Lazy Video ─────────────────── */} + +
+ {/* Badge */} ))} - -
+
+
+ {/* Sleek Stats Card Section */}