forked from GCA-Classroom/01-prj-personal-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (47 loc) · 1.93 KB
/
Copy pathscript.js
File metadata and controls
60 lines (47 loc) · 1.93 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
(function () {
const savedTheme = localStorage.getItem('portfolio-theme');
if (savedTheme === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
function setTheme(theme) {
const themeToggle = document.querySelector('.theme-toggle');
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('portfolio-theme', theme);
if (!themeToggle) {
return;
}
const themeToggleIcon = themeToggle.querySelector('i');
const isDark = theme === 'dark';
themeToggle.setAttribute('aria-pressed', String(isDark));
themeToggle.setAttribute('aria-label', isDark ? 'Switch to light mode' : 'Switch to dark mode');
if (themeToggleIcon) {
themeToggleIcon.className = isDark ? 'fa-solid fa-sun' : 'fa-solid fa-moon';
}
}
document.addEventListener('DOMContentLoaded', () => {
const themeToggle = document.querySelector('.theme-toggle');
const initialTheme = localStorage.getItem('portfolio-theme') === 'dark' ? 'dark' : 'light';
const timelineItems = document.querySelectorAll('.experience-card');
setTheme(initialTheme);
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches || !('IntersectionObserver' in window)) {
timelineItems.forEach((item) => item.classList.add('is-visible'));
} else {
const timelineObserver = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.18 });
timelineItems.forEach((item) => timelineObserver.observe(item));
}
if (!themeToggle) {
return;
}
themeToggle.addEventListener('click', () => {
const nextTheme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
setTheme(nextTheme);
});
});
})();