-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.js
39 lines (36 loc) · 1.29 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
const menuBars = document.getElementById('menu-bars');
const overlay = document.getElementById('overlay');
const nav1 = document.getElementById('nav-1');
const nav2 = document.getElementById('nav-2');
const nav3 = document.getElementById('nav-3');
const nav4 = document.getElementById('nav-4');
const nav5 = document.getElementById('nav-5');
const navItems = [nav1, nav2, nav3, nav4, nav5];
// Control Navigation Animation
function navAnimation(direction1, direction2) {
navItems.forEach((nav, i) => {
nav.classList.replace(`slide-${direction1}-${i + 1}`, `slide-${direction2}-${i + 1}`);
});
}
function toggleNav() {
// Toggle: Menu Bars Open/Closed
menuBars.classList.toggle('change');
// Toggle: Menu Active
overlay.classList.toggle('overlay-active');
if (overlay.classList.contains('overlay-active')) {
// Animate In - Overlay
overlay.classList.replace('overlay-slide-left', 'overlay-slide-right');
// Animate In - Nav Items
navAnimation('out', 'in');
} else {
// Animate Out - Overlay
overlay.classList.replace('overlay-slide-right', 'overlay-slide-left');
// Animate Out - Nav Items
navAnimation('in', 'out');
}
}
// Event Listeners
menuBars.addEventListener('click', toggleNav);
navItems.forEach((nav) => {
nav.addEventListener('click', toggleNav);
});