mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-31 02:07:21 +00:00
22 lines
615 B
JavaScript
22 lines
615 B
JavaScript
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);
|
|
});
|
|
});
|