-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
150 lines (141 loc) · 5.51 KB
/
Copy pathscript.js
File metadata and controls
150 lines (141 loc) · 5.51 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* ============================================================
Arunachalam Kasi — interactions
============================================================ */
(function () {
"use strict";
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// Screenshot/no-animation mode: ?_shot reveals everything immediately (used for visual QA).
const shotMode = /[?&]_shot/.test(location.search);
/* ---------- Nav: scrolled state ---------- */
const nav = document.getElementById("nav");
const onScroll = () => {
if (window.scrollY > 24) nav.classList.add("scrolled");
else nav.classList.remove("scrolled");
};
onScroll();
window.addEventListener("scroll", onScroll, { passive: true });
/* ---------- Mobile menu ---------- */
const toggle = document.getElementById("navToggle");
const menu = document.getElementById("mobileMenu");
if (toggle && menu) {
const menuLinks = menu.querySelectorAll("a");
menu.inert = true; // closed links out of tab order until opened
const setOpen = (open) => {
nav.classList.toggle("open", open);
toggle.setAttribute("aria-expanded", String(open));
toggle.setAttribute("aria-label", open ? "Close menu" : "Open menu");
menu.style.transform = open ? "translateY(0)" : "";
menu.setAttribute("aria-hidden", String(!open));
menu.inert = !open;
document.body.style.overflow = open ? "hidden" : "";
if (open && menuLinks[0]) menuLinks[0].focus();
else if (!open) toggle.focus();
};
toggle.addEventListener("click", () => setOpen(!nav.classList.contains("open")));
menuLinks.forEach((a) => a.addEventListener("click", () => setOpen(false)));
document.addEventListener("keydown", (e) => {
if (e.key === "Escape" && nav.classList.contains("open")) setOpen(false);
});
}
/* ---------- Scroll reveals ---------- */
const reveals = document.querySelectorAll(".reveal");
if (reduceMotion || shotMode || !("IntersectionObserver" in window)) {
reveals.forEach((el) => el.classList.add("in"));
} else {
const io = new IntersectionObserver(
(entries) => {
entries.forEach((e) => {
if (e.isIntersecting) {
e.target.classList.add("in");
io.unobserve(e.target);
}
});
},
{ threshold: 0.12, rootMargin: "0px 0px -8% 0px" }
);
reveals.forEach((el) => io.observe(el));
}
/* ---------- Animated counters ---------- */
const counters = document.querySelectorAll("[data-count]");
const runCounter = (el) => {
const target = parseFloat(el.dataset.count);
const decimals = parseInt(el.dataset.dec || "0", 10);
const suffix = el.dataset.suffix || "";
if (reduceMotion) {
el.textContent = target.toFixed(decimals) + suffix;
return;
}
const duration = 1400;
let start = null;
const tick = (ts) => {
if (!start) start = ts;
const p = Math.min((ts - start) / duration, 1);
const eased = 1 - Math.pow(1 - p, 3); // easeOutCubic
const val = target * eased;
el.textContent = val.toFixed(decimals) + (p === 1 ? suffix : "");
if (p < 1) requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
};
if ("IntersectionObserver" in window) {
const cio = new IntersectionObserver(
(entries) => {
entries.forEach((e) => {
if (e.isIntersecting) {
runCounter(e.target);
cio.unobserve(e.target);
}
});
},
{ threshold: 0.6 }
);
counters.forEach((el) => cio.observe(el));
} else {
counters.forEach(runCounter);
}
/* ---------- Card spotlight (pointer-follow glow) ---------- */
if (!reduceMotion && window.matchMedia("(pointer:fine)").matches) {
document.querySelectorAll(".card").forEach((card) => {
card.addEventListener("pointermove", (e) => {
const r = card.getBoundingClientRect();
card.style.setProperty("--mx", ((e.clientX - r.left) / r.width) * 100 + "%");
card.style.setProperty("--my", ((e.clientY - r.top) / r.height) * 100 + "%");
});
});
}
/* ---------- Active section in nav ---------- */
const sections = document.querySelectorAll("section[id], header[id]");
const navAnchors = Array.from(document.querySelectorAll(".nav-links a"));
const linkFor = (id) => navAnchors.find((a) => a.getAttribute("href") === "#" + id);
if ("IntersectionObserver" in window && navAnchors.length) {
const sio = new IntersectionObserver(
(entries) => {
entries.forEach((e) => {
const link = linkFor(e.target.id);
if (!link) return;
if (e.isIntersecting) {
navAnchors.forEach((a) => a.style.removeProperty("color"));
link.style.color = "var(--ink)";
}
});
},
{ threshold: 0.5 }
);
sections.forEach((s) => sio.observe(s));
}
/* ---------- Smooth-scroll for same-page anchors (offset for nav) ---------- */
document.querySelectorAll('a[href^="#"]').forEach((a) => {
a.addEventListener("click", (e) => {
const id = a.getAttribute("href").slice(1);
if (!id) return;
const target = document.getElementById(id);
if (!target) return;
e.preventDefault();
const top = target.getBoundingClientRect().top + window.scrollY - 8;
window.scrollTo({ top, behavior: reduceMotion ? "auto" : "smooth" });
history.replaceState(null, "", "#" + id);
});
});
/* ---------- Year stamp guard (keep footer honest) ---------- */
// Static 2026 in markup; nothing to compute.
})();