This repository was archived by the owner on Sep 16, 2021. It is now read-only.
forked from Compec/boundatacamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
52 lines (42 loc) · 1.33 KB
/
main.js
File metadata and controls
52 lines (42 loc) · 1.33 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
window.addEventListener('load', function() {
// Menu START
(function() {
var hamburger = {
navToggle: document.querySelector('.nav-toggle'),
nav: document.querySelector('nav'),
doToggle: function(e) {
// e.preventDefault();
this.navToggle.classList.toggle('expanded');
this.nav.classList.toggle('expanded');
}
};
hamburger.navToggle.addEventListener('click', function(e) { hamburger.doToggle(e); });
hamburger.nav.addEventListener('click', function(e) { hamburger.doToggle(e); });
}());
// Menu END
// SmoothScroll START
var scroll = new SmoothScroll('[data-scroll]', {
offset: 80
});
// SmoothScroll END
});
const nav = document.getElementById('nav');
const navItems = document.querySelectorAll('[data-type="navItem"]');
let isNavOpen = false;
function toggleNav() {
if (isNavOpen) {
navItems.forEach(a => a.classList.replace('fadeIn', 'fadeOut'));
nav.classList.remove('sidenav-open');
isNavOpen = false;
} else {
nav.classList.add('sidenav-open');
navItems.forEach(a => a.classList.replace('fadeOut', 'fadeIn'));
isNavOpen = true;
}
}
window.addEventListener('click', (e) => {
if (isNavOpen && e.target !== nav && e.target.id !== 'navToggle'&& e.target.id !== 'intoggle') {
toggleNav();
e.stopPropagation();
}
});