Skip to content

Commit b6cd521

Browse files
Disabled scrolling in hamburger menu for small devices (#105)
1 parent f930335 commit b6cd521

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

script.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ mobileMenuBtn.addEventListener('click', () => {
258258
mobileMenuBtn.classList.toggle('active');
259259
navItems.classList.toggle('active');
260260

261+
// Toggle body scrolling for small devices
262+
if (navItems.classList.contains('active')) {
263+
document.body.style.overflow = 'hidden';
264+
} else {
265+
document.body.style.overflow = 'auto';
266+
}
267+
261268
// Update accessibility attributes
262269
const isOpen = navItems.classList.contains('active');
263270
mobileMenuBtn.setAttribute('aria-expanded', isOpen);
@@ -271,6 +278,7 @@ document.addEventListener('click', (e) => {
271278
navItems.classList.remove('active');
272279
mobileMenuBtn.setAttribute('aria-expanded', 'false');
273280
mobileMenuBtn.setAttribute('aria-label', 'Open mobile menu');
281+
document.body.style.overflow = 'auto';
274282
}
275283
});
276284

@@ -281,6 +289,7 @@ window.addEventListener('resize', () => {
281289
navItems.classList.remove('active');
282290
mobileMenuBtn.setAttribute('aria-expanded', 'false');
283291
mobileMenuBtn.setAttribute('aria-label', 'Open mobile menu');
292+
document.body.style.overflow = 'auto';
284293
}
285294
});
286295

0 commit comments

Comments
 (0)