-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
32 lines (27 loc) · 985 Bytes
/
script.js
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
document.getElementById('dark-mode-toggle').addEventListener('click', function() {
document.body.classList.toggle('dark-mode');
if (document.body.classList.contains('dark-mode')) {
this.textContent = '☀️';
} else {
this.textContent = '🌙';
}
});
const yearLinks = document.querySelectorAll('.year-nav a');
const yearSections = document.querySelectorAll('.year');
window.addEventListener('scroll', () => {
let currentYear = '';
yearSections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const windowHeight = window.innerHeight;
if (window.pageYOffset >= sectionTop - windowHeight / 3 && window.pageYOffset < sectionTop + sectionHeight - windowHeight / 3) {
currentYear = section.id;
}
});
yearLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + currentYear) {
link.classList.add('active');
}
});
});