Created
July 31, 2022 09:45
-
-
Save ramzs/f0c982aa6689b01fc90f24bfa317bb68 to your computer and use it in GitHub Desktop.
Мобильное меню с оверлеем и автовысотой
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mainSliderDesc.controller.control = mainSlider; | |
mainSlider.controller.control = mainSliderDesc; | |
let menuButton = document.querySelector('.menu-button'); | |
let mobileNav = document.querySelector('.mobile-nav'); | |
let mobileNavClose = document.querySelector('.mobile-nav__close'); | |
let overlay = document.querySelector('.overlay'); | |
let body = document.querySelector('body'); | |
let openMenu = function () { | |
menuButton.classList.toggle('active'); | |
mobileNav.classList.toggle('open'); | |
mobileNav.classList.toggle('hide'); | |
overlay.classList.toggle('active'); | |
body.classList.toggle('overflow'); | |
appHeight(); | |
}; | |
menuButton.addEventListener('click', openMenu, true); | |
mobileNavClose.addEventListener('click', openMenu, true); | |
overlay.addEventListener('click', openMenu, true); | |
// Auto height | |
const appHeight = () => { | |
let vh = window.innerHeight * 0.01; | |
document.documentElement.style.setProperty('--vh', `${vh}px`); | |
}; | |
appHeight(); | |
window.addEventListener('resize', appHeight); | |
window.addEventListener('load', appHeight); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment