Jquery on click function not reseting on browser resize -


i have following code slides column in left right , nudges right of column on right , again (a bit facebook app). works fine on document ready not on resize. after resizing starts act strangely. though doing previous function , not registering new function on resize.

function domenu() {  var $trigger = $(".icon-menu-2"); var $menu = $(".c_left"); var width = $(window).width();  if ((width < 870) && (width > 750)) {     var status = 'closed';      $('.icon-list').on('click', function(event){         if ( status === 'closed' ){             $menu.animate({                 width: 0,                 marginleft: -200,                 display: 'toggle'             }, 'fast');             $(".content_right, .navbar").animate({                 marginright: 0,                 display: 'toggle'             }, 'fast');             return status = 'open';          } else if ( status === 'open' ) {           $menu.animate({                 width: 200,                 marginleft: 0,                 display: 'toggle'             }, 'fast');             $(".content_right, .navbar").animate({                 marginright: -120,                 display: 'toggle'             }, 'fast');             return status = 'closed';         }     }); }  if (width < 750) {     var status = 'closed';     $('.icon-list').on('click', function(event){         if ( status === 'closed' ){             $menu.animate({                 width: 0,                 marginleft: -200,                 display: 'toggle'             }, 'fast');             $(".content_right, .navbar").animate({                 marginleft: 0,                 display: 'toggle'             }, 'fast');             return status = 'open';          } else if ( status === 'open' ) {             $menu.animate({                 width: 200,                 marginleft: 0,                 display: 'toggle'             }, 'fast');             $(".content_right, .navbar").animate({                 marginleft: 200,                 display: 'toggle'             }, 'fast');             return status = 'closed';         }     });              }  } $(document).ready(domenu); $(window).resize(domenu); 

edit - changed toggle() on('click', function(event) suggested below still have same problems functions not working on resize.

instead of toggle can use flags.

var status = 'closed'; $('.foo').on('click', function(event){     if ( status === 'closed' ){         //...         return status = 'open';      } else if ( status === 'open' ) {         //..         return status = 'closed';      } }); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -