-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (35 loc) · 1.17 KB
/
script.js
File metadata and controls
41 lines (35 loc) · 1.17 KB
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
const navbar = document.querySelector(".navbar");
const navbarOffsetTop = navbar.offsetTop;
const sections = document.querySelectorAll("section");
const navbarLinks = document.querySelectorAll(".navbar-link");
const progress = document.querySelector(".progress-bars-wrapper");
const progressBarPercents = [97, 89, 85, 87, 80, 70, 50];
window.addEventListener("scroll", () => {
mainFn();
});
const mainFn = () => {
if (window.pageYOffset >= navbarOffsetTop) {
navbar.classList.add("sticky");
} else {
navbar.classList.remove("sticky");
}
sections.forEach((section, i) => {
if (window.pageYOffset >= section.offsetTop - 10) {
navbarLinks.forEach((navbarLink) => {
navbarLink.classList.remove("change");
});
navbarLinks[i].classList.add("change");
}
});
if (window.pageYOffset + window.innerHeight >= progress.offsetTop) {
document.querySelectorAll(".progress-percent").forEach((el, i) => {
el.style.width = `${progressBarPercents[i]}%`;
el.previousElementSibling.firstElementChild.textContent =
progressBarPercents[i];
});
}
};
mainFn();
window.addEventListener("resize", () => {
window.location.reload();
});