-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
42 lines (36 loc) · 1.25 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
function toggleNavi() {
console.log("du du du");
let nav = document.getElementsByClassName('js-nav')[0];
let overlay = document.getElementsByClassName('js-overlay')[0];
if (!nav.classList.contains("dn")) {
setTimeout(function(){
// wait for the css animation to almost finish before dn
overlay.classList.toggle('dn');
nav.classList.toggle('dn');
}, 900);
} else {
overlay.classList.toggle('dn');
nav.classList.toggle('dn');
}
nav.classList.toggle('fadeout');
overlay.classList.toggle('fadeout');
nav.classList.toggle('fadein');
overlay.classList.toggle('fadein');
}
function naviOutsideClick() {
let nav = document.getElementsByClassName('js-nav')[0];
if (!nav.classList.contains("dn")) {
toggleNavi();
}
}
// EVENT LISTENERS
var menu = document.getElementsByClassName('js-menu')[0];
menu.addEventListener('click', toggleNavi, false);
var navCloseAreas = document.getElementsByClassName('js-nav-close');
for (var i = 0; i < navCloseAreas.length; i++) {
navCloseAreas[i].addEventListener('click', naviOutsideClick, false);
}
var navLinks = document.getElementsByClassName('js-link');
for (var i = 0; i < navLinks.length; i++) {
navLinks[i].addEventListener('click', naviOutsideClick, false);
}