From f0f5f5c96e287fd61c7b19fd2bcd311616aced3e Mon Sep 17 00:00:00 2001 From: Kristina Date: Wed, 14 Feb 2024 12:38:32 +0200 Subject: [PATCH] Update burger-menu.js --- src/js/burger-menu.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/js/burger-menu.js b/src/js/burger-menu.js index d1b7e2f..40ac2ea 100644 --- a/src/js/burger-menu.js +++ b/src/js/burger-menu.js @@ -9,8 +9,7 @@ const homeButton = document.querySelector('.link-home'); backdrop: document.querySelector('.background-menu'), }; - const backdrop = document.querySelector('.backdrop'); - backdrop.classList.add('is-hidden'); + refs.modal.classList.add('is-hidden'); refs.openModalBtn.addEventListener('click', function () { toggleModal(); @@ -21,8 +20,8 @@ const homeButton = document.querySelector('.link-home'); enableScroll(); }); - document.addEventListener('click', function (event) { - if (!refs.modal.contains(event.target) && !refs.openModalBtn.contains(event.target)) { + refs.backdrop.addEventListener('click', function (event) { + if (event.target === refs.backdrop) { toggleModal(); enableScroll(); }