Skip to content

Instantly share code, notes, and snippets.

@mapsam
Created September 24, 2014 20:33
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 mapsam/c0697e147be5b2614625 to your computer and use it in GitHub Desktop.
Save mapsam/c0697e147be5b2614625 to your computer and use it in GitHub Desktop.
menu toggling & resizing screen precautions
var nav = $('#nav'),
menu = $('#nav .menu'),
navButton = $('.nav-expand');
// mobile button dropdown
$('button.nav-expand').on('click', function(){
menu.slideToggle(200);
navButton.toggleClass('open');
});
var blocked = false,
threshold = 705;
$(window).resize(function(){
menuCheck($(window).outerWidth(true), blocked, threshold);
});
function menuCheck(w, b, t) {
if (w>t && !b) {
menu.show();
blocked = !b;
$('.nav-expand').removeClass('open');
} else if (w<=t && b) {
menu.hide();
blocked = !b;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment