Skip to content

Commit

Permalink
Reduce 9 lines of JS :-)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cszach committed Oct 17, 2023
1 parent f99e8a7 commit 402802c
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 402802c

Please sign in to comment.