23 lines
600 B
JavaScript
23 lines
600 B
JavaScript
export function initReveals() {
|
|
const nodes = document.querySelectorAll(".reveal");
|
|
if (!nodes.length) return;
|
|
|
|
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
nodes.forEach((el) => el.classList.add("is-revealed"));
|
|
return;
|
|
}
|
|
|
|
const io = new IntersectionObserver(
|
|
(entries) => {
|
|
for (const entry of entries) {
|
|
if (!entry.isIntersecting) continue;
|
|
entry.target.classList.add("is-revealed");
|
|
io.unobserve(entry.target);
|
|
}
|
|
},
|
|
{ rootMargin: "-80px", threshold: 0.01 }
|
|
);
|
|
|
|
nodes.forEach((el) => io.observe(el));
|
|
}
|