-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (24 loc) · 1022 Bytes
/
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
const menuToggleIcon = document.getElementById('menu-toggle-icon');
const navMobile = document.getElementById('nav');
const headerElement = document.getElementById('header');
const navLinks = document.querySelectorAll('.nav-mobile .list-link');
const toggleMenu = () => {
navMobile.classList.toggle('active');
headerElement.classList.toggle('active');
}
menuToggleIcon.addEventListener('click', toggleMenu);
const headerScrollEvent = () => {
if(this.scrollY >= 30){
headerElement.classList.add('active-scroll');
} else{
headerElement.classList.remove('active-scroll')
}
}
window.addEventListener('scroll', headerScrollEvent);
navLinks.forEach(link => link.addEventListener('click', () => {
navMobile.classList.remove('active');
headerElement.classList.remove('active');
let current = document.getElementsByClassName('current');
current[0].className = current[0].className.replace(' current', '');
link.className += ' current';
}));