Created
September 28, 2013 01:37
-
-
Save kosinix/6737462 to your computer and use it in GitHub Desktop.
Using debounce on window resize to perform responsive javascript actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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