main.js 809 B

123456789101112131415161718192021222324
  1. const navigation = document.querySelector('[data-navigation]');
  2. const mobileNavigation = navigation.querySelector('[data-mobile-navigation]');
  3. const body = document.querySelector('body');
  4. const mobileNavigationToggle = navigation.querySelector(
  5. '[data-mobile-navigation-toggle]',
  6. );
  7. function toggleMobileNavigation() {
  8. if (mobileNavigation.hidden) {
  9. body.classList.add('no-scroll');
  10. mobileNavigation.hidden = false;
  11. mobileNavigationToggle.setAttribute('aria-expanded', 'true');
  12. } else {
  13. body.classList.remove('no-scroll');
  14. mobileNavigation.hidden = true;
  15. mobileNavigationToggle.setAttribute('aria-expanded', 'false');
  16. }
  17. }
  18. document.addEventListener('DOMContentLoaded', () => {
  19. mobileNavigationToggle.addEventListener('click', () => {
  20. toggleMobileNavigation();
  21. });
  22. });