From 0ceb2281861c3e70391f9f5320d71cf88fe62418 Mon Sep 17 00:00:00 2001 From: Serhii Reshetniak Date: Sun, 14 Apr 2024 19:04:01 +0300 Subject: [PATCH] Make buttons work --- src/index.html | 2 +- src/main.js | 26 ++++++++++++++++---------- src/partials/header.html | 2 +- src/partials/mobile-menu.html | 27 +++++---------------------- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/index.html b/src/index.html index e609264..e543fa2 100644 --- a/src/index.html +++ b/src/index.html @@ -31,6 +31,6 @@ - + diff --git a/src/main.js b/src/main.js index 12ec4b4..b874569 100644 --- a/src/main.js +++ b/src/main.js @@ -1,11 +1,17 @@ -'use strict'; +(() => { + const mobileMenu = { + modal: document.querySelector('#mobile-menu'), + menuOpenBtn: document.querySelector('.button-menu-open'), + menuCloseBtn: document.querySelector('.modal-btn'), + menuCloseByLink: document.querySelector('.modal-menu-link'), + menuCloseByLinkShop: document.querySelector('.modal-menu-link-shop'), + }; -function openMobileMenu() { - const modal = document.getElementById('mobile-menu'); - modal.classList.add('is-open'); -} - -function closeMobileMenu() { - const modal = document.getElementById('mobile-menu'); - modal.classList.remove('is-open'); -} + mobileMenu.menuOpenBtn.addEventListener('click', toogleIsOpen); + mobileMenu.menuCloseBtn.addEventListener('click', toogleIsOpen); + mobileMenu.menuCloseByLink.addEventListener('click', toogleIsOpen); + mobileMenu.menuCloseByLinkShop.addEventListener('click', toogleIsOpen); + function toogleIsOpen() { + mobileMenu.modal.classList.toggle('is-open'); + } +})(); diff --git a/src/partials/header.html b/src/partials/header.html index a623724..e520da9 100644 --- a/src/partials/header.html +++ b/src/partials/header.html @@ -31,7 +31,7 @@ -