File size: 615 Bytes
2409829 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
const VISIBILITY_COVERAGE_FRACTION = 0.25;
window.addEventListener("DOMContentLoaded", () => {
const players = document.querySelectorAll("[data-auto-play]");
players.forEach((player) => {
if (!(player instanceof HTMLVideoElement)) return;
let loaded = false;
new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (!loaded && entry.intersectionRatio > VISIBILITY_COVERAGE_FRACTION) {
player.removeAttribute("preload");
player.setAttribute("autoplay", "");
loaded = true;
};
});
}, { threshold: VISIBILITY_COVERAGE_FRACTION })
.observe(player);
});
});
|