-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile-navbar.js
45 lines (38 loc) · 1.14 KB
/
mobile-navbar.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
43
44
45
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);
}
animateLinks() {
this.navLinks.forEach((link, index) => {
link.style.animation
? (link.style.animation = "")
: (link.style.animation = `navLinkFade 0.5s 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();