I have a click event for my hamburger menu. To position this menu correctly I have used a couple variables. My only problem is when the screen size changes I need to update the values of these variables so that the menu always stays in the correct position. I have tried using a jQuery(window).resize function to reset the values but its not working and I don't get why.
jQuery("#button").click(function(){
var nav = jQuery("#nav_container");
var head_h = jQuery('#fullhead_wrap').height();
var nav_height = jQuery(window).height() - head_h;
jQuery(window).resize(function(){
var new_head_h = jQuery('#fullhead_wrap').height();
head_h = new_head_h;
var new_nav_height = jQuery(window).height() - new_head_h;
nav_height = new_nav_height;
});
jQuery("#button span").toggleClass("open");
jQuery("body").toggleClass("overflow");
jQuery('.header_nav li').toggleClass('link_fall');
nav.toggleClass('menu_open');
nav.height(nav_height);
if(nav.hasClass('menu_open')){
nav.css('top', head_h);
}else{
nav.css('top', '0');
}
});
#buttonyou install a newresizeevent listener. That crashes. Also try withhtml,bodyinstead ofwindow.