-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (55 loc) · 1.92 KB
/
Copy pathscript.js
File metadata and controls
60 lines (55 loc) · 1.92 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
53
54
55
56
57
58
59
60
// Reveal sections as they scroll into view (progressive enhancement —
// content is fully visible without JS via the <noscript> / reduced-motion paths).
const reveals = document.querySelectorAll(".reveal");
if ("IntersectionObserver" in window) {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.14, rootMargin: "0px 0px -24px 0px" }
);
reveals.forEach((section, index) => {
section.style.transitionDelay = `${Math.min(index * 60, 200)}ms`;
observer.observe(section);
});
} else {
reveals.forEach((section) => section.classList.add("is-visible"));
}
// Frost the sticky header once the page is scrolled.
const header = document.querySelector(".site-header");
if (header) {
const onScroll = () => header.classList.toggle("scrolled", window.scrollY > 8);
onScroll();
window.addEventListener("scroll", onScroll, { passive: true });
}
// Cursor-follow spotlight — desktop pointers only, and never when the user
// has asked for reduced motion. rAF-throttled to one DOM write per frame.
const spotlight = document.querySelector(".spotlight");
const finePointer = window.matchMedia("(hover: hover) and (pointer: fine)").matches;
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (spotlight && finePointer && !reducedMotion) {
let queued = false;
let px = 0;
let py = 0;
window.addEventListener(
"pointermove",
(event) => {
px = event.clientX;
py = event.clientY;
if (!queued) {
queued = true;
requestAnimationFrame(() => {
spotlight.style.setProperty("--mx", `${px}px`);
spotlight.style.setProperty("--my", `${py}px`);
queued = false;
});
}
},
{ passive: true }
);
}