From 5e253ef331c91e4be97edc801c3dc22660672bec Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 8 Nov 2024 18:14:44 -0800 Subject: [PATCH] reset main page video when going out of frame --- src/components/marquee/Marquee.astro | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/marquee/Marquee.astro b/src/components/marquee/Marquee.astro index 8c27752..2e00021 100644 --- a/src/components/marquee/Marquee.astro +++ b/src/components/marquee/Marquee.astro @@ -67,19 +67,20 @@ const videos = [ const intersectionOptions = { root: marquee, rootMargin: "0px", - threshold: 1.0, + threshold: 0.0, }; + const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { + const video = entry.target as HTMLVideoElement; if (!entry.isIntersecting) { - //@ts-expect-error - entry.target.pause(); - entry.target.removeAttribute("autoplay") - entry.target.removeAttribute("data-active") + video.pause(); + video.removeAttribute("autoplay") + video.removeAttribute("data-active") + video.currentTime = 0; } else { - //@ts-expect-error - entry.target.play(); - entry.target.setAttribute("data-active","") + video.play(); + video.setAttribute("data-active","") } }); },intersectionOptions);