Created
November 22, 2013 22:06
-
-
Save matrixfox/7607674 to your computer and use it in GitHub Desktop.
jQuery Media Queries, add your code and resize the browser.
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
var delay = (function(){ | |
var timer = 0; | |
return function(callback, ms){ | |
clearTimeout (timer); | |
timer = setTimeout(callback, ms); | |
}; | |
})(); | |
$(function() { | |
var pause = 100; | |
// will only process code within delay(function() { ... }) every 100ms. | |
$(window).resize(function() { | |
delay(function() { | |
var width = $(window).width(); | |
if( width >= 768 && width <= 959 ) { | |
// code for tablet view | |
} else if( width >= 480 && width <= 767 ) { | |
// code for mobile landscape | |
} else if( width <= 479 ) { | |
// code for mobile portrait | |
} | |
}, pause ); | |
}); | |
$(window).resize(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment