-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
16 lines (16 loc) · 750 Bytes
/
Copy pathscript.js
File metadata and controls
16 lines (16 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var navLinks = document.querySelectorAll(".nav-link");
function checkScrollPos() {
var ids = ["section_2", "section_3", "section_4", "section_7"], scrolls = [];
ids.forEach(id => scrolls.push(document.getElementById(id).offsetTop));
scrolls[0] = 0;
scrolls.forEach((scroll, counter) => {
var scrollTop = window.scrollY;
if (Math.abs(scrollTop - scroll) < 50) {
navLinks[counter].parentElement.classList.add("active");
}
});
}
window.addEventListener("scroll", () => {
navLinks.forEach(el => el.parentElement.classList.remove("active"));
checkScrollPos();
});