Created
October 26, 2014 17:25
-
-
Save sausman/b9c2563acd0a0b4b96b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Store $('body') and $('.mainMenu') in variables outside of the event handler | |
// This way they only need to be looked up once and not on every click | |
var $body = $('body'); | |
var $mainMenu = $(".mainMenu"); | |
$body.click(function(e){ | |
// Since you're only checking the className you can use `hasClass` here instead of `is` | |
// http://jsperf.com/jquery-is-vs-hasclass | |
if ( $(e.target).hasClass("js-menuToggle") ) { | |
$mainMenu.toggleClass("mainMenu--visible"); | |
$body.toggleClass('js-fixScroll'); | |
} | |
else { | |
$mainMenu.removeClass("mainMenu--visible"); | |
$body.removeClass('js-fixScroll'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment