-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
43 lines (36 loc) · 1.21 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
const navbar = document.querySelector(".navbar");
const navbarOffsetTop = navbar.offsetTop;
const sections = document.querySelectorAll("section, header");
const navbarLinks = document.querySelectorAll(".navbar-link");
const progress = document.querySelector(".progress-bars-wrapper");
const progressPercents = document.querySelectorAll(".progress-bar-percent");
const progressBarPercents = [
...document.querySelectorAll(".progress-bar-text span"),
];
window.addEventListener("scroll", () => {
initApp();
});
const initApp = () => {
if (window.pageYOffset >= navbarOffsetTop) {
navbar.classList.add("sticky");
} else {
navbar.classList.remove("sticky");
}
sections.forEach((section, index) => {
if (window.pageYOffset >= section.offsetTop - 50) {
navbarLinks.forEach((link) => {
link.classList.remove("active");
});
navbarLinks[index].classList.add("active");
}
});
if (window.pageYOffset + window.innerHeight >= progress.offsetTop) {
progressPercents.forEach((ele, index) => {
ele.style.width = `${Number(progressBarPercents[index].textContent)}%`;
});
}
};
initApp();
// window.addEventListener("resize", () => {
// window.location.reload();
// });