Skip to content

Instantly share code, notes, and snippets.

@freshyill
Created November 29, 2012 23:01
Show Gist options
  • Save freshyill/4172511 to your computer and use it in GitHub Desktop.
Save freshyill/4172511 to your computer and use it in GitHub Desktop.
Media Queries in jQuery
// Media queries in jQuery
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$(function() {
var pause = 100;
$(window).resize(function() {
delay(function() {
var width = $(window).width();
if ( width >= 1140 ) { // desktop-wide
# Do something
} else if ( width >= 1024 && width <= 1039 ) { // desktop-small
# Do something
} else if ( width >= 768 && width <= 1023 ) { // tablet-portrait
# Do something
} else if ( width >= 568 && width <= 767 ) { // phone-wide-landscape
# Do something
} else if ( width >= 480 && width <= 567 ) { // phone-landscape
# Do something
} else if ( width <= 479 ) { // phone-portrait
# Do something
}
}, pause );
});
$(window).resize();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment