aboutsummaryrefslogtreecommitdiff
path: root/src/component
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-08-10 16:05:38 +0200
committerWilliam Hergès <william@herges.fr>2025-08-10 16:05:59 +0200
commit993877357dc3c4c4dcac838209e56ca4c6f79959 (patch)
treed46c8ad450e03a9fcd33ac3a3883aa7e9eb260d3 /src/component
parent8b193399ee31add29bfe1b53cbf754bad23fef78 (diff)
perf(video): display thumbnail for mobile
Diffstat (limited to 'src/component')
-rw-r--r--src/component/VideoAuto.astro17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/component/VideoAuto.astro b/src/component/VideoAuto.astro
index ddfe1c8..8746b68 100644
--- a/src/component/VideoAuto.astro
+++ b/src/component/VideoAuto.astro
@@ -1,16 +1,23 @@
---
-const { src } = Astro.props;
+const { src, thumb } = Astro.props;
---
-<video muted loop>
- <source src={src} />
-</video>
+<img src={thumb} data-video={src} alt="Video thumbnail" />
<script>
window.addEventListener("load", () => {
- document.querySelectorAll("video").forEach((video) => {
+ document.querySelectorAll("img[data-video]").forEach((img) => {
if (window.screen.width < 1000) return;
+ const video = document.createElement("video");
+ video.muted = true;
+ video.defaultMuted = true;
+ video.loop = true;
video.autoplay = true;
+ const source = document.createElement("source");
+ source.src = img.getAttribute("data-video");
+ video.appendChild(source);
+ img.parentNode.insertBefore(video, img);
+ img.parentNode.removeChild(img);
});
});
</script>