class MobileMenu { constructor() { this.burgerMenu = document.getElementById('burgerMenu'); this.mobileMenu = document.getElementById('mobileMenu'); this.closeMenu = document.getElementById('closeMenu'); this.menuOverlay = document.getElementById('menuOverlay'); this.init(); } init() { // Открытие меню this.burgerMenu.addEventListener('click', () => { this.openMenu(); }); // Закрытие меню по кнопке this.closeMenu.addEventListener('click', () => { this.closeMenuHandler(); }); // Закрытие меню по клику на оверлей this.menuOverlay.addEventListener('click', () => { this.closeMenuHandler(); }); // Закрытие меню по клавише Escape document.addEventListener('keydown', (e) => { if (e.key === 'Escape') { this.closeMenuHandler(); } }); // Закрытие меню при клике на ссылку const mobileLinks = document.querySelectorAll('.mobile-nav-link'); mobileLinks.forEach(link => { link.addEventListener('click', () => { this.closeMenuHandler(); }); }); } openMenu() { this.mobileMenu.classList.add('active'); this.menuOverlay.classList.add('active'); this.burgerMenu.classList.add('active'); document.body.style.overflow = 'hidden'; } closeMenuHandler() { this.mobileMenu.classList.remove('active'); this.menuOverlay.classList.remove('active'); this.burgerMenu.classList.remove('active'); document.body.style.overflow = ''; } } // Инициализация меню при загрузке страницы document.addEventListener('DOMContentLoaded', () => { new MobileMenu(); });