diff options
| author | William Hergès <william@herges.fr> | 2025-08-10 16:11:41 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-10 16:11:41 +0200 |
| commit | e8a3e86272f3da820a23c53da13da93ddbb37475 (patch) | |
| tree | bbe132fe8944957f9afc6e59275b2afa689e46c7 /src/component/VideoAuto.astro | |
| parent | 993877357dc3c4c4dcac838209e56ca4c6f79959 (diff) | |
fix(mosaic): wrong display for lines with video
Diffstat (limited to 'src/component/VideoAuto.astro')
| -rw-r--r-- | src/component/VideoAuto.astro | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/component/VideoAuto.astro b/src/component/VideoAuto.astro index 8746b68..bcf23a3 100644 --- a/src/component/VideoAuto.astro +++ b/src/component/VideoAuto.astro @@ -5,9 +5,13 @@ const { src, thumb } = Astro.props; <img src={thumb} data-video={src} alt="Video thumbnail" /> <script> - window.addEventListener("load", () => { + const updateVideo = () => { document.querySelectorAll("img[data-video]").forEach((img) => { if (window.screen.width < 1000) return; + const parent = img.parentNode; + if (parent == null) { + throw new Error("Invalid video"); + } const video = document.createElement("video"); video.muted = true; video.defaultMuted = true; @@ -16,8 +20,19 @@ const { src, thumb } = Astro.props; const source = document.createElement("source"); source.src = img.getAttribute("data-video"); video.appendChild(source); - img.parentNode.insertBefore(video, img); - img.parentNode.removeChild(img); + console.log(img); + parent.insertBefore(video, img); + parent.removeChild(img); + }); + }; + + window.addEventListener("load", () => { + document.querySelectorAll("img[data-video]").forEach((img) => { + const parent = img.parentNode; + if (parent == null) { + throw new Error("Invalid video."); + } + parent.addEventListener("updatevideo", updateVideo); }); }); </script> |
