-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (34 loc) · 1.21 KB
/
script.js
File metadata and controls
39 lines (34 loc) · 1.21 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
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,87,85,75,80]
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(navbarLinks => {
navbarLinks.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();
// })