style(video): Refactor blurred video container layout and improve sync handling
- Remove max-height constraint from blurred-video-container for flexible sizing - Simplify background video positioning from centered transform to full coverage - Add scale transform to background video for better blur effect coverage - Update background video to use full width/height instead of 110% dimensions - Add opacity transition state for background video loading - Improve event listener cleanup with named handler functions - Add error handling for background video playback with catch fallback - Add loadeddata event listener to track video loading state - Override post-media-item video background for transparent blurred container - Enhance video synchronization reliability between main and background layers
This commit is contained in:
+10
-6
@@ -360,7 +360,6 @@ a.btn-primary:visited {
|
||||
.blurred-video-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-height: 360px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -370,14 +369,14 @@ a.btn-primary:visited {
|
||||
|
||||
.blurred-video-bg {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 110%;
|
||||
height: 110%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
filter: blur(20px) brightness(0.6);
|
||||
pointer-events: none;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.blurred-video-main {
|
||||
@@ -389,6 +388,11 @@ a.btn-primary:visited {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* Override post-media-item video styles for blurred container */
|
||||
.post-media-item .blurred-video-container video {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.video-embed-container {
|
||||
position: relative;
|
||||
padding-bottom: 56.25%;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useRef, useEffect } from 'react';
|
||||
import { useRef, useEffect, useState } from 'react';
|
||||
|
||||
interface BlurredVideoProps {
|
||||
src: string;
|
||||
@@ -11,25 +11,34 @@ export default function BlurredVideo({ src, onClick }: BlurredVideoProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const mainVideoRef = useRef<HTMLVideoElement>(null);
|
||||
const bgVideoRef = useRef<HTMLVideoElement>(null);
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Sync playback between main and background videos
|
||||
const mainVideo = mainVideoRef.current;
|
||||
const bgVideo = bgVideoRef.current;
|
||||
|
||||
if (mainVideo && bgVideo) {
|
||||
// Sync playback between main and background videos
|
||||
const syncTime = () => {
|
||||
if (Math.abs(mainVideo.currentTime - bgVideo.currentTime) > 0.1) {
|
||||
bgVideo.currentTime = mainVideo.currentTime;
|
||||
}
|
||||
};
|
||||
|
||||
const handlePlay = () => bgVideo.play().catch(() => {});
|
||||
const handlePause = () => bgVideo.pause();
|
||||
const handleLoaded = () => setIsLoaded(true);
|
||||
|
||||
mainVideo.addEventListener('seeked', syncTime);
|
||||
mainVideo.addEventListener('play', () => bgVideo.play());
|
||||
mainVideo.addEventListener('pause', () => bgVideo.pause());
|
||||
mainVideo.addEventListener('play', handlePlay);
|
||||
mainVideo.addEventListener('pause', handlePause);
|
||||
mainVideo.addEventListener('loadeddata', handleLoaded);
|
||||
|
||||
return () => {
|
||||
mainVideo.removeEventListener('seeked', syncTime);
|
||||
mainVideo.removeEventListener('play', handlePlay);
|
||||
mainVideo.removeEventListener('pause', handlePause);
|
||||
mainVideo.removeEventListener('loadeddata', handleLoaded);
|
||||
};
|
||||
}
|
||||
}, []);
|
||||
@@ -47,6 +56,7 @@ export default function BlurredVideo({ src, onClick }: BlurredVideoProps) {
|
||||
preload="metadata"
|
||||
className="blurred-video-bg"
|
||||
aria-hidden="true"
|
||||
style={{ opacity: isLoaded ? 1 : 0 }}
|
||||
/>
|
||||
{/* Main video */}
|
||||
<video
|
||||
|
||||
Reference in New Issue
Block a user