blob: 8746b6844e76d42538c132a9429b1189f96321e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
---
const { src, thumb } = Astro.props;
---
<img src={thumb} data-video={src} alt="Video thumbnail" />
<script>
window.addEventListener("load", () => {
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>
|