Add Menu and Navigation
This commit is contained in:
31
js/nav.js
Normal file
31
js/nav.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const CLS = {
|
||||
open: 'Nav--open',
|
||||
};
|
||||
|
||||
export default class Nav {
|
||||
constructor(cfg) {
|
||||
this.el = cfg.el;
|
||||
this.menu = cfg.menu;
|
||||
|
||||
this.attachEvents();
|
||||
}
|
||||
|
||||
attachEvents() {
|
||||
this.menu.el.addEventListener('click', () => {
|
||||
this.menu.hideMenu();
|
||||
this.openNav();
|
||||
});
|
||||
this.el.querySelector('.Nav-close').addEventListener('click', () => {
|
||||
this.menu.showMenu();
|
||||
this.closeNav();
|
||||
});
|
||||
}
|
||||
|
||||
openNav() {
|
||||
this.el.classList.add(CLS.open);
|
||||
}
|
||||
|
||||
closeNav() {
|
||||
this.el.classList.remove(CLS.open);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user