-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (54 loc) · 2.25 KB
/
Copy pathscript.js
File metadata and controls
59 lines (54 loc) · 2.25 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
(function () {
"use strict";
/* Theme toggle */
var toggle = document.getElementById("theme-toggle");
toggle.addEventListener("click", function () {
var dark = document.documentElement.classList.toggle("dark");
localStorage.setItem("theme", dark ? "dark" : "light");
});
/* Mobile menu */
var nav = document.getElementById("nav");
var menuBtn = document.getElementById("menu-btn");
menuBtn.addEventListener("click", function () {
var open = nav.classList.toggle("menu-open");
menuBtn.setAttribute("aria-expanded", open ? "true" : "false");
});
document.querySelectorAll(".mobile-panel a").forEach(function (a) {
a.addEventListener("click", function () {
nav.classList.remove("menu-open");
menuBtn.setAttribute("aria-expanded", "false");
});
});
/* Scroll reveal — content stays visible without JS */
var reveals = document.querySelectorAll(".reveal");
if ("IntersectionObserver" in window) {
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (e) {
if (e.isIntersecting) {
e.target.classList.add("in");
io.unobserve(e.target);
}
});
}, { threshold: 0.12, rootMargin: "0px 0px -8% 0px" });
reveals.forEach(function (el) { io.observe(el); });
} else {
reveals.forEach(function (el) { el.classList.add("in"); });
}
/* Active nav highlighting */
var links = document.querySelectorAll(".nav-links a");
var map = {};
links.forEach(function (l) { map[l.getAttribute("href").slice(1)] = l; });
var secObs = new IntersectionObserver(function (entries) {
entries.forEach(function (e) {
var link = map[e.target.id];
if (!link) return;
if (e.isIntersecting) {
links.forEach(function (l) { l.classList.remove("active"); });
link.classList.add("active");
}
});
}, { rootMargin: "-30% 0px -60% 0px" });
document.querySelectorAll("main section[id]").forEach(function (s) { secObs.observe(s); });
/* Year */
document.getElementById("year").textContent = new Date().getFullYear();
})();