Created
November 29, 2012 23:01
-
-
Save freshyill/4172511 to your computer and use it in GitHub Desktop.
Media Queries in jQuery
This file contains hidden or 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
// 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