-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanding.js
More file actions
50 lines (40 loc) · 1.34 KB
/
landing.js
File metadata and controls
50 lines (40 loc) · 1.34 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
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
function revealOnScroll() {
const revealables = document.querySelectorAll("[data-reveal]");
if (!revealables.length) return;
if (prefersReducedMotion.matches || !("IntersectionObserver" in window)) {
revealables.forEach((element) => element.classList.add("is-visible"));
return;
}
const observer = new IntersectionObserver(
(entries, activeObserver) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
entry.target.classList.add("is-visible");
activeObserver.unobserve(entry.target);
});
},
{
threshold: 0.2,
rootMargin: "0px 0px -10% 0px"
}
);
revealables.forEach((element) => observer.observe(element));
}
function bindReducedMotionListener() {
const handler = () => {
if (!prefersReducedMotion.matches) return;
document
.querySelectorAll("[data-reveal]")
.forEach((element) => element.classList.add("is-visible"));
};
if ("addEventListener" in prefersReducedMotion) {
prefersReducedMotion.addEventListener("change", handler);
} else if ("addListener" in prefersReducedMotion) {
prefersReducedMotion.addListener(handler);
}
}
document.addEventListener("DOMContentLoaded", () => {
revealOnScroll();
bindReducedMotionListener();
});