Skip to content

Instantly share code, notes, and snippets.

@kosinix
Created September 28, 2013 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosinix/6737462 to your computer and use it in GitHub Desktop.
Save kosinix/6737462 to your computer and use it in GitHub Desktop.
Using debounce on window resize to perform responsive javascript actions
jQuery(document).ready(function($){
on_resize(function() {
var w = $(window).width();
if(w>=740){ //740-x
jQuery('.main-nav').show();
} else if (w<740){ //0-739
jQuery('.main-nav').hide();
}
})();
})
//Debounced - https://github.com/louisremi/jquery-smartresize
function on_resize(c,t){onresize=function(){clearTimeout(t);t=setTimeout(c,100)};return c};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment