-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (30 loc) · 1.91 KB
/
Copy pathscript.js
File metadata and controls
47 lines (30 loc) · 1.91 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
42
43
44
45
46
47
const scrollPosition = document.documentElement.scrollTop
let aboutPosition = 0
let skillsPosition = document.getElementById("skills").offsetTop
let portfolioPosition = document.getElementById("portfolio").offsetTop
let contactPosition = document.body.offsetHeight - window.innerHeight
let scrollSetter = ()=>{
if(window.scrollY >= aboutPosition && window.scrollY < skillsPosition){
document.getElementById("nav-about").classList.add("current-section")
document.getElementById("nav-skills").classList.remove("current-section")
document.getElementById("nav-portfolio").classList.remove("current-section")
document.getElementById("nav-contact").classList.remove("current-section")
} else if ( window.scrollY >= skillsPosition && window.scrollY < portfolioPosition){
document.getElementById("nav-skills").classList.add("current-section")
document.getElementById("nav-about").classList.remove("current-section")
document.getElementById("nav-portfolio").classList.remove("current-section")
document.getElementById("nav-contact").classList.remove("current-section")
} else if (window.scrollY >= portfolioPosition && window.scrollY < contactPosition){
document.getElementById("nav-portfolio").classList.add("current-section")
document.getElementById("nav-skills").classList.remove("current-section")
document.getElementById("nav-about").classList.remove("current-section")
document.getElementById("nav-contact").classList.remove("current-section")
} else if ( window.scrollY >= contactPosition){
document.getElementById("nav-contact").classList.add("current-section")
document.getElementById("nav-portfolio").classList.remove("current-section")
document.getElementById("nav-skills").classList.remove("current-section")
document.getElementById("nav-about").classList.remove("current-section")
}
}
scrollSetter()
window.addEventListener('scroll', scrollSetter)