$(document).ready(function(){ $("#menu_toggle_control").on('click',function(){ $("#left-menu").animate({ width: 'toggle', opacity: 'toggle' }, 'slow'); resizeMain(); }); function resizeMain(){ if($('#left-menu').css('display')!=='none'){ $("#main").css("width",($(window).outerWidth()-$("#left-menu").outerWidth())+"px"); } else{ $("#main").css("width",($(window).outerWidth())+"px"); }; }; $(window).load(function(){ resizeMain(); }); $(window).resize(function(){ resizeMain(); }); });
How to make the left menu hide when the button is pressed and the main occupies the entire width, and when you press the button back, the left menu appears and the main occupies the remaining width of the window?