-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
24 lines (19 loc) · 785 Bytes
/
main.js
File metadata and controls
24 lines (19 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(() => {
const year = document.getElementById('current-year');
if (year) year.textContent = String(new Date().getFullYear());
const sections = [...document.querySelectorAll('section[id], header[id]')];
const navLinks = [...document.querySelectorAll('.nav-links a[href^="#"]')];
const setActiveLink = () => {
const middle = window.scrollY + window.innerHeight * 0.35;
let current = sections[0]?.id;
sections.forEach((section) => {
if (middle >= section.offsetTop) current = section.id;
});
navLinks.forEach((link) => {
const isActive = link.getAttribute('href') === `#${current}`;
link.classList.toggle('active', isActive);
});
};
window.addEventListener('scroll', setActiveLink, { passive: true });
setActiveLink();
})();