Skip to content

Instantly share code, notes, and snippets.

@jgraffin
Last active May 21, 2016 02:51
Show Gist options
  • Save jgraffin/a949cf5c7aaa67b0e379c5de00550cf4 to your computer and use it in GitHub Desktop.
Save jgraffin/a949cf5c7aaa67b0e379c5de00550cf4 to your computer and use it in GitHub Desktop.
Mobile menu with pure JS
document.addEventListener('DOMContentLoaded', mainReady);
var global = null;
function mainReady(){
var global = new Global();
global.init();
}
function Global(){
}
Global.prototype = {
constructor: Global,
init: function(){
'use strict';
this._navigationMobile();
},
_navigationMobile: function(){
(function(window, document, html){
var $button_open = document.querySelector('.js-button-open');
var $button_close = document.querySelector('.js-button-close');
var $navigation_mobile = document.querySelector('.js-navigation-mobile');
$button_open.addEventListener('click', function() {
$navigation_mobile.classList.add('js-is-open');
document.body.classList.add('js-is-open');
document.body.style.overflow = 'hidden';
html.style.overflowY = 'hidden';
});
$button_close.addEventListener('click', function() {
$navigation_mobile.classList.remove('js-is-open');
document.body.classList.remove('js-is-open');
document.body.style.overflow = 'visible';
html.style.overflowY = 'auto';
});
})(window, document, document.querySelector('html'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment