-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
38 lines (29 loc) · 1.15 KB
/
Copy pathmain.js
File metadata and controls
38 lines (29 loc) · 1.15 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
const navMenu = document.getElementById('nav-menu'),
toggleMenu = document.getElementById('nav-toggle'),
closeMenu = document.getElementById('nav-close')
toggleMenu.addEventListener('click', ()=>{
navMenu.classList.toggle('show')
})
closeMenu.addEventListener('click', ()=>{
navMenu.classList.remove('show')
})
const navLink = document.querySelectorAll('.nav__link')
function linkAction(){
navMenu.classList.remove('show')
}
navLink.forEach(n => n.addEventListener('click', linkAction))
const sections = document.querySelectorAll('section[id]')
window.addEventListener('scroll', scrollActive)
function scrollActive(){
const scrollY = window.pageYOffset
sections.forEach(current =>{
const sectionHeight = current.offsetHeight
const sectionTop = current.offsetTop - 50
sectionId = current.getAttribute('id')
if(scrollY > sectionTop && scrollY <= sectionTop +sectionHeight){
document.querySelector('.nav__menu a[href*='+ sectionId +']').classList.add('active')
}else{
document.querySelector('.nav__menu a[href*='+ sectionId +']').classList.remove('active')
}
})
}