Skip to content

Instantly share code, notes, and snippets.

@wolfcoder
Created June 11, 2022 12:01
Show Gist options
  • Save wolfcoder/d892143d2247cf30c152a79ee2072380 to your computer and use it in GitHub Desktop.
Save wolfcoder/d892143d2247cf30c152a79ee2072380 to your computer and use it in GitHub Desktop.
navigation menu open overlay
class NavigationII{
//1. Describe and initiate our object
constructor() {
this.openMenu = document.getElementById('open-menu')
this.closeMenu = document.getElementById('close-menu')
this.mobileMenu = document.getElementById('mobile-menu')
this.htmlBody = document.getElementsByTagName('body')
this.events()
}
// 2. Events
events() {
this.openMenu.addEventListener("click", () => this.openMenuOverlay())
this.closeMenu.addEventListener("click", () => this.closeMenuOverlay())
}
// 3. methods (function, action...)
openMenuOverlay(){
this.mobileMenu.classList.remove("hidden")
this.scrollToggle()
}
closeMenuOverlay(){
this.mobileMenu.classList.add("hidden")
this.scrollToggle()
}
scrollToggle() {
if (this.htmlBody[0].style.overflow === '' || this.htmlBody[0].style.overflow === 'scroll') {
this.htmlBody[0].style.overflow = 'hidden'
} else {
this.htmlBody[0].style.removeProperty('overflow')
}
}
}
export default NavigationII
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment