Skip to content

Instantly share code, notes, and snippets.

@ckpicker
Created June 5, 2018 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckpicker/6d52d3c93ed01ca1c1ddad9b029a01b4 to your computer and use it in GitHub Desktop.
Save ckpicker/6d52d3c93ed01ca1c1ddad9b029a01b4 to your computer and use it in GitHub Desktop.
Using vanilla js instead of jquery
import delegate from 'delegate';
const el = {
siteHeader: document.querySelector('.site-header'),
};
/**
* @function toggleMenu
* @description Toggle the menu open and closed
*/
const toggleMenu = () => {
const searchItems = document.querySelector('.site-header__midstrip--search-items');
const iconHeaderMenu = document.querySelector('.icon-header-menu');
if (searchItems && iconHeaderMenu) {
searchItems.classList.toggle('is--active');
iconHeaderMenu.classList.toggle('mobile-item--color--grey');
}
};
/**
* @function bindEvents
* @description Bind the events for this module here.
*/
const bindEvents = () => {
delegate(el.siteHeader, '[data-js="site-header__nav-menu--btn"]', 'click', toggleMenu);
};
/**
* @module Navigation
* @description Javascript opening and closing menu
*/
const navigationMenu = () => {
bindEvents();
};
export default navigationMenu;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment