Created
December 13, 2012 08:25
-
-
Save DavidWells/4274990 to your computer and use it in GitHub Desktop.
jQuery :: Responsive Design Media Query Helper Function
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
| <script> | |
| 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(); | |
| }); | |
| <script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment