-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (47 loc) · 1.87 KB
/
Copy pathscript.js
File metadata and controls
52 lines (47 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(() => {
// Staggered reveal on scroll (kept minimal and respectful of reduced-motion).
const revealEls = Array.from(document.querySelectorAll(".reveal"));
if ("IntersectionObserver" in window) {
const io = new IntersectionObserver(
(entries) => {
for (const e of entries) {
if (!e.isIntersecting) continue;
e.target.classList.add("is-visible");
io.unobserve(e.target);
}
},
{ root: null, threshold: 0.12 }
);
for (const el of revealEls) io.observe(el);
} else {
for (const el of revealEls) el.classList.add("is-visible");
}
// Mark missing local videos (keeps the page usable when MP4s are not present yet).
const videoCards = Array.from(document.querySelectorAll(".media-card"));
for (const card of videoCards) {
const video = card.querySelector("video");
if (!video) continue;
const markMissing = () => card.classList.add("is-missing");
const clearMissing = () => card.classList.remove("is-missing");
// Some browsers surface the error on <source>, others on <video>.
video.addEventListener("error", markMissing, true);
for (const srcEl of Array.from(video.querySelectorAll("source"))) {
srcEl.addEventListener("error", markMissing, true);
}
video.addEventListener("loadeddata", clearMissing, true);
video.addEventListener("canplay", clearMissing, true);
// Best-effort autoplay (works with muted + playsinline in modern browsers).
if (video.muted) {
const tryPlay = () => {
const p = video.play();
if (p && typeof p.catch === "function") p.catch(() => {});
};
video.addEventListener("loadedmetadata", tryPlay, { once: true });
tryPlay();
}
// Heuristic fallback: if nothing loads shortly after page load, show hint.
setTimeout(() => {
if (video.readyState === 0) markMissing();
}, 1200);
}
})();