Skip to content

Instantly share code, notes, and snippets.

@mihailsitnic
Created August 13, 2018 11:57
Show Gist options
  • Save mihailsitnic/4d0a256a7db8ad6b2fb29f5ffe2b87cd to your computer and use it in GitHub Desktop.
Save mihailsitnic/4d0a256a7db8ad6b2fb29f5ffe2b87cd to your computer and use it in GitHub Desktop.
'use strict';
/* Header Menu Button
/* ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## */
const headerMenuButton = document.getElementsByClassName('drop-menu__link')[0];
const dropdownMenu = document.getElementsByClassName('ul-drop')[0];
headerMenuButton.onclick = () => {
headerMenuButton.classList.toggle('drop-menu__link--active');
dropdownMenu.classList.toggle('ul-drop--active');
}
/* Close Drop Down Menu
/* ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## */
const closeDropDownMenuOnClickOutside = (e) => {
const target = e.target;
const menu = target.closest('menu');
if (!menu) {
headerMenuButton.classList.remove('drop-menu__link--active');
dropdownMenu.classList.remove('ul-drop--active');
}
}
document.body.addEventListener('click', closeDropDownMenuOnClickOutside);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment