-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (41 loc) · 1.51 KB
/
script.js
File metadata and controls
50 lines (41 loc) · 1.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
const themeToggle = document.querySelector("#themeToggle");
const filterButtons = document.querySelectorAll(".filter-button");
const projectCards = document.querySelectorAll(".project-card");
const navLinks = document.querySelectorAll(".rail-nav a");
const sections = [...navLinks]
.map((link) => document.querySelector(link.getAttribute("href")))
.filter(Boolean);
const savedTheme = localStorage.getItem("portfolio-theme");
if (savedTheme === "dark") {
document.body.classList.add("dark-mode");
}
themeToggle.addEventListener("click", () => {
document.body.classList.toggle("dark-mode");
localStorage.setItem(
"portfolio-theme",
document.body.classList.contains("dark-mode") ? "dark" : "light"
);
});
filterButtons.forEach((button) => {
button.addEventListener("click", () => {
const filter = button.dataset.filter;
filterButtons.forEach((item) => item.classList.remove("active"));
button.classList.add("active");
projectCards.forEach((card) => {
const shouldShow = filter === "all" || card.dataset.category === filter;
card.classList.toggle("is-hidden", !shouldShow);
});
});
});
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
navLinks.forEach((link) => {
link.classList.toggle("active", link.getAttribute("href") === `#${entry.target.id}`);
});
});
},
{ rootMargin: "-45% 0px -45% 0px", threshold: 0.01 }
);
sections.forEach((section) => observer.observe(section));