From 402802cb02c734ba795ece329cf7b0500b726f12 Mon Sep 17 00:00:00 2001 From: Zach Date: Mon, 16 Oct 2023 21:18:35 -0400 Subject: [PATCH] Reduce 9 lines of JS :-) I just realized that since the dark overlay has pointer-events: auto, it already disables scrolling when visible, and there is no need for overflow-x: hidden on the body. --- script.js | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/script.js b/script.js index 3d198d7..b2b6c16 100644 --- a/script.js +++ b/script.js @@ -4,16 +4,12 @@ document.addEventListener('DOMContentLoaded', () => { const navigationLinks = navBar.querySelectorAll('li'); const hamburgerCheckbox = navBar.querySelector('.peer'); - if (hamburgerCheckbox.checked) { - document.body.classList.add('overflow-hidden'); - } - // Hamburger navigation navigationLinks.forEach(navigationLink => { - navigationLink.addEventListener('click', () => { - closeNavigationMenu(); - }); + navigationLink.addEventListener('click', () => { + hamburgerCheckbox.checked = false; + }); }); // Navbar appears on scroll down and hides on scroll up @@ -35,26 +31,13 @@ document.addEventListener('DOMContentLoaded', () => { navBar.classList.remove('-translate-y-full'); } - // Disable scrolling when navigation menu is visible - - hamburgerCheckbox.addEventListener('change', (e) => { - if (e.target.checked) { - document.body.classList.add('overflow-hidden'); - } - }); - // Close navigation menu when the dark overlay is clicked on const darkOverlay = navBar.querySelector('.bg-black'); darkOverlay.addEventListener('click', () => { - closeNavigationMenu(); - }); - - function closeNavigationMenu() { - document.body.classList.remove('overflow-hidden'); hamburgerCheckbox.checked = false; - } + }); // particles.js