Created
April 14, 2013 22:34
-
-
Save mandelbro/5384516 to your computer and use it in GitHub Desktop.
Triggers jQuery events when some key mediaQuery breakpoints are hit
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
(function($){ | |
$(function() { | |
var mqls = [window.matchMedia("(min-width: 1900px)"), window.matchMedia("(max-width: 780px)"), window.matchMedia("(max-width: 480px)")], | |
handleOrientationChange = function(mql) { | |
switch(mql.media) { | |
case '(min-width: 1900px)' : | |
$(document).trigger('matchesHD.mediaQuery', { 'mql' : mql }); | |
break; | |
case '(max-width: 780px)' : | |
$(document).trigger('matchesTabletPortrait.mediaQuery', { 'mql' : mql }); | |
break; | |
case '(max-width: 480px)' : | |
$(document).trigger('matchesMobile.mediaQuery', { 'mql' : mql }); | |
break; | |
} | |
if(mql.matches) $(document).trigger('matches.mediaQuery', { 'mql' : mql }); | |
}, | |
mql, i; | |
for(i in mqls) { | |
mql = mqls[i]; | |
mql.addListener(handleOrientationChange); | |
handleOrientationChange(mql); | |
} | |
}); | |
})(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment