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 {
|
.blurred-video-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-height: 360px;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -370,14 +369,14 @@ a.btn-primary:visited {
|
|||||||
|
|
||||||
.blurred-video-bg {
|
.blurred-video-bg {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 0;
|
||||||
left: 50%;
|
left: 0;
|
||||||
transform: translate(-50%, -50%);
|
width: 100%;
|
||||||
width: 110%;
|
height: 100%;
|
||||||
height: 110%;
|
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
filter: blur(20px) brightness(0.6);
|
filter: blur(20px) brightness(0.6);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
transform: scale(1.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.blurred-video-main {
|
.blurred-video-main {
|
||||||
@@ -389,6 +388,11 @@ a.btn-primary:visited {
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Override post-media-item video styles for blurred container */
|
||||||
|
.post-media-item .blurred-video-container video {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
.video-embed-container {
|
.video-embed-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
padding-bottom: 56.25%;
|
padding-bottom: 56.25%;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useRef, useEffect } from 'react';
|
import { useRef, useEffect, useState } from 'react';
|
||||||
|
|
||||||
interface BlurredVideoProps {
|
interface BlurredVideoProps {
|
||||||
src: string;
|
src: string;
|
||||||
@@ -11,25 +11,34 @@ export default function BlurredVideo({ src, onClick }: BlurredVideoProps) {
|
|||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const mainVideoRef = useRef<HTMLVideoElement>(null);
|
const mainVideoRef = useRef<HTMLVideoElement>(null);
|
||||||
const bgVideoRef = useRef<HTMLVideoElement>(null);
|
const bgVideoRef = useRef<HTMLVideoElement>(null);
|
||||||
|
const [isLoaded, setIsLoaded] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Sync playback between main and background videos
|
|
||||||
const mainVideo = mainVideoRef.current;
|
const mainVideo = mainVideoRef.current;
|
||||||
const bgVideo = bgVideoRef.current;
|
const bgVideo = bgVideoRef.current;
|
||||||
|
|
||||||
if (mainVideo && bgVideo) {
|
if (mainVideo && bgVideo) {
|
||||||
|
// Sync playback between main and background videos
|
||||||
const syncTime = () => {
|
const syncTime = () => {
|
||||||
if (Math.abs(mainVideo.currentTime - bgVideo.currentTime) > 0.1) {
|
if (Math.abs(mainVideo.currentTime - bgVideo.currentTime) > 0.1) {
|
||||||
bgVideo.currentTime = mainVideo.currentTime;
|
bgVideo.currentTime = mainVideo.currentTime;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePlay = () => bgVideo.play().catch(() => {});
|
||||||
|
const handlePause = () => bgVideo.pause();
|
||||||
|
const handleLoaded = () => setIsLoaded(true);
|
||||||
|
|
||||||
mainVideo.addEventListener('seeked', syncTime);
|
mainVideo.addEventListener('seeked', syncTime);
|
||||||
mainVideo.addEventListener('play', () => bgVideo.play());
|
mainVideo.addEventListener('play', handlePlay);
|
||||||
mainVideo.addEventListener('pause', () => bgVideo.pause());
|
mainVideo.addEventListener('pause', handlePause);
|
||||||
|
mainVideo.addEventListener('loadeddata', handleLoaded);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
mainVideo.removeEventListener('seeked', syncTime);
|
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"
|
preload="metadata"
|
||||||
className="blurred-video-bg"
|
className="blurred-video-bg"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
|
style={{ opacity: isLoaded ? 1 : 0 }}
|
||||||
/>
|
/>
|
||||||
{/* Main video */}
|
{/* Main video */}
|
||||||
<video
|
<video
|
||||||
|
|||||||
Reference in New Issue
Block a user