-
Notifications
You must be signed in to change notification settings - Fork 8
/
script.js
48 lines (38 loc) · 1.27 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
44
45
46
47
48
// Menu show Y hidden
const navMenu = document.getElementById('nav-menu'),
toggleMenu = document.getElementById('nav-toggle'),
closeMenu = document.getElementById('nav-close');
// Show
toggleMenu.addEventListener('click', ()=>{
navMenu.classList.toggle('show');
});
// Hidden
closeMenu.addEventListener('click', ()=>{
navMenu.classList.remove('show');
});
// Remove menu
const navLink = document.querySelectorAll('.nav__link');
function linkAction()
{
navMenu.classList.remove('show');
};
navLink.forEach(n => n.addEventListener('click', linkAction));
// Scroll ections active link
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')
}
})
}