From b461c6cf322927837a0505ac297febeebcd65666 Mon Sep 17 00:00:00 2001 From: Shanmuga Krishnan S M Date: Tue, 4 Aug 2026 09:03:39 +0530 Subject: [PATCH] fix(ui): activate dark video overlay only when video is playing --- .../LazyVideoHero/LazyVideoHero.tsx | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/components/LazyVideoHero/LazyVideoHero.tsx b/src/components/LazyVideoHero/LazyVideoHero.tsx index c6c0045..d0eb0f5 100644 --- a/src/components/LazyVideoHero/LazyVideoHero.tsx +++ b/src/components/LazyVideoHero/LazyVideoHero.tsx @@ -8,6 +8,7 @@ export default function LazyVideoHero({ children }: LazyVideoHeroProps) { const containerRef = useRef(null); const videoRef = useRef(null); const [isIntersecting, setIsIntersecting] = useState(true); + const [isVideoPlaying, setIsVideoPlaying] = useState(false); useEffect(() => { const container = containerRef.current; @@ -18,17 +19,13 @@ export default function LazyVideoHero({ children }: LazyVideoHeroProps) { setIsIntersecting(entry.isIntersecting); if (videoRef.current) { if (entry.isIntersecting) { - videoRef.current.play().catch(() => { - // Ignore autoplay restrictions if browser blocks - }); + videoRef.current.play().catch(() => {}); } else { videoRef.current.pause(); } } }, - { - threshold: 0.1, // Pause when 90% of section is out of view - } + { threshold: 0.1 } ); observer.observe(container); @@ -40,6 +37,18 @@ export default function LazyVideoHero({ children }: LazyVideoHeroProps) { return (
+ {/* Ambient Mesh Backdrop (Used when video is loading or absent) */} +
+
+
+
+ {/* ─── Optimized Video Background ────────────────────────────────────────── */}
setIsVideoPlaying(true)} + onError={() => setIsVideoPlaying(false)} className="w-full h-full object-cover transition-opacity duration-700" style={{ filter: 'contrast(1.08) brightness(0.85) saturate(1.05)', - opacity: isIntersecting ? 1 : 0, + opacity: (isIntersecting && isVideoPlaying) ? 1 : 0, contain: 'strict', }} > @@ -68,13 +79,15 @@ export default function LazyVideoHero({ children }: LazyVideoHeroProps) { - {/* High-Contrast Glassmorphic Overlay Gradient */} -
+ {/* High-Contrast Glassmorphic Overlay Gradient (Only active when video plays) */} + {isVideoPlaying && ( +
+ )}
{/* ─── Hero Content ──────────────────────────────────────────────────────── */}