I'm trying to make a push style menu which shifts the content over to one side in order to reveal a menu list. So far the menu works fine when opening and closing, although i would also like to add functionality which allows the user to close the menu by clicking anywhere in the content section.
I'm not really sure of how I can tie the 'close' function to the body container once the menu has been opened.
I've attempted using .bind() and .trigger() but I'm new to javascript/jquery and don't really understand how to make it work in this situation.
Here is the current function which opens/closes the menu...
$('.menu-button').click(function(){
if(parseInt($('.site-menu').css('left')) == -144){
$('.site-menu').addClass('site-menu-pushr');
$('.site-header, .container-site-content').addClass('site-view-pushr');
}
else {
linkClickUnpush();
}
});
Since I use classes to carry out the animation I figured I could make a function which allows the content to be clicked on once the menu has been opened, but no dice! I don't know how to make the function run each time the menu has been opened since adding it to the click event above just breaks it.
function contentCloseMenu(){
if($('.site-header, .container-site-content').hasClass('site-menu-pushr')){
$('.site-header, .container-site-content').click(function(){
linkClickUnpush();
});
}
};
Any help is greatly appreciated!