-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
35 lines (28 loc) · 976 Bytes
/
main.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
33
34
35
//closing side navigation for mobile and tablet screens
const closeBtn = document.querySelector("#close");
closeBtn.addEventListener("click", () => {
const linksContainer = document.querySelector("#navbarNavDropdown");
linksContainer.classList.remove("show");
});
// navigation-link active on scroll
window.addEventListener("scroll", () => {
const scrollPosition = scrollY;
const sections = document.querySelectorAll(".section[id]");
let current = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop;
if (scrollPosition >= sectionTop) {
current = section.getAttribute("id");
}
});
//removing classlink from every nav-links as default
const navLinks = document.querySelectorAll(".navbar__nav-item a ");
navLinks.forEach((li) => {
li.classList.remove("active");
// console.log(li);
console.log(li.getAttribute);
if (li.dataset.id === current) {
li.classList.add("active");
}
});
});