-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobile-navbar.js
More file actions
51 lines (37 loc) · 1.15 KB
/
mobile-navbar.js
File metadata and controls
51 lines (37 loc) · 1.15 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
class MobileNavBar {
constructor(mobileMenu, navList, navLinks) {
this.mobileMenu = document.querySelector(mobileMenu);
this.navList = document.querySelector(navList);
this.navLinks = document.querySelectorAll(navLinks);
this.activeClass = "active";
this.handleClick = this.handleClick.bind(this);
this.handleClick = this.handleClick.bind();
}
animateLinks() {
this.navLinks.forEach((link, index) => {
link.style.animation
? (link.style.animation = "")
: (link.style.animation = `navLinkFade 0.5 ease forwards ${index / 7 + 0.3}s`);
});
}
handleClick() {
this.navList.classList.toggle(this.activeClass);
this.mobileMenu.classList.toggle(this.activeClass);
this.animateLinks();
}
addClickEvent() {
this.mobileMenu.addEventListener("click", this.handleClick);
}
init() {
if (this.mobileMenu) {
this.addClickEvent();
}
return this;
}
}
const mobileNavBar = new MobileNavBar(
".mobile-menu",
".nav-list",
".nav-list li",
);
mobileNavBar.init();