Commit 0c70de15 by Ravindra Kanojiya

updated video or image option both in video section

1 parent 78ba8b7b
import React, { useRef, useEffect, useState } from "react"; import React, { useRef, useEffect, useState } from "react";
import { Container } from "react-bootstrap"; import Image from "next/image";
import { cleanImage } from "../services/imageHandling"; import { cleanImage } from "../services/imageHandling";
const Video = ({productData}) => { const Video = ({ productData }) => {
const mediaRef = useRef(null);
const videoRef = useRef(null);
const [isVisible, setIsVisible] = useState(false); const [isVisible, setIsVisible] = useState(false);
useEffect(() => { const media = productData?.video;
const observer = new IntersectionObserver(
([entry]) => { const isVideo = media?.mime?.startsWith("video/");
if (entry.isIntersecting) { const isImage = media?.mime?.startsWith("image/");
setIsVisible(true);
useEffect(() => {
// 👇 Stop observing after first visibility const observer = new IntersectionObserver(
observer.unobserve(entry.target); ([entry]) => {
} if (entry.isIntersecting) {
}, setIsVisible(true);
{ threshold: 0.5 } observer.unobserve(entry.target);
); }
},
{ threshold: 0.5 }
);
if (videoRef.current) observer.observe(videoRef.current); if (mediaRef.current) observer.observe(mediaRef.current);
return () => { return () => {
if (videoRef.current) observer.unobserve(videoRef.current); if (mediaRef.current) observer.unobserve(mediaRef.current);
}; };
}, []); }, []);
if (!media?.url) return null;
return ( return (
<section className="video_sec"> <section className="video_sec">
<div className="custom_containers"> <div className="custom_containers">
<video
ref={videoRef} {/* VIDEO */}
autoPlay {isVideo && (
muted <video
loop ref={mediaRef}
playsInline autoPlay
className={`w-100 video-animate ${isVisible ? "video-visible" : ""}`} muted
> loop
<source src={cleanImage(productData?.video?.url)} type="video/mp4" /> playsInline
Your browser does not support the video tag. className={`w-100 video-animate ${isVisible ? "video-visible" : ""}`}
</video> >
<source src={cleanImage(media?.url)} type={media?.mime || "video/mp4"} />
Your browser does not support the video tag.
</video>
)}
{/* IMAGE */}
{isImage && (
<div
ref={mediaRef}
className={`w-100 video-animate ${isVisible ? "video-visible" : ""}`}
>
<Image
src={cleanImage(media?.url)}
alt={media?.alternativeText || media?.name || "Media"}
width={media?.width || 868}
height={media?.height || 560}
className="w-100"
style={{ objectFit: "cover" }}
/>
</div>
)}
</div> </div>
</section> </section>
); );
}; };
export default Video; export default Video;
\ No newline at end of file \ No newline at end of file
...@@ -345,6 +345,9 @@ button.cust-swiper-button-next { ...@@ -345,6 +345,9 @@ button.cust-swiper-button-next {
.video-visible { .video-visible {
transform: scale(1.1); transform: scale(1.1);
} }
.video-visible img{
height: 100%;
}
.video_sec{ .video_sec{
overflow: hidden; overflow: hidden;
} }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!