Skip to content

Commit 61a495d

Browse files
Disabled scrolling in hamburger menu for mobile devices
1 parent 5378520 commit 61a495d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

script.js

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

261+
// Toggle body scrolling
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);
264271
mobileMenuBtn.setAttribute('aria-label', isOpen ? 'Close mobile menu' : 'Open mobile menu');
265272
});
266273

274+
267275
// Close mobile menu when clicking outside
268276
document.addEventListener('click', (e) => {
269277
if (!navItems.contains(e.target) && !mobileMenuBtn.contains(e.target) && navItems.classList.contains('active')) {
270278
mobileMenuBtn.classList.remove('active');
271279
navItems.classList.remove('active');
272280
mobileMenuBtn.setAttribute('aria-expanded', 'false');
273281
mobileMenuBtn.setAttribute('aria-label', 'Open mobile menu');
282+
document.body.style.overflow = 'auto';
274283
}
275284
});
276285

@@ -281,6 +290,7 @@ window.addEventListener('resize', () => {
281290
navItems.classList.remove('active');
282291
mobileMenuBtn.setAttribute('aria-expanded', 'false');
283292
mobileMenuBtn.setAttribute('aria-label', 'Open mobile menu');
293+
document.body.style.overflow = 'auto';
284294
}
285295
});
286296

0 commit comments

Comments
 (0)