Created
December 11, 2012 14:54
-
-
Save nkcmr/4259104 to your computer and use it in GitHub Desktop.
this bit of code watches the conditions of the viewport and runs the appropriate query.
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 supportsOrientationChange = "onorientationchange" in window, //Check if device supports orientation change listening | |
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; //If so listen for orientation change, if not listen for resizing | |
window.addEventListener(orientationEvent, function() { | |
console.log('Orientation did Change!!'); | |
for(i=0;i<queries.length;i++){ //Parse through queries | |
var mq = window.matchMedia(queries[i].match_this); | |
if(mq.matches){ | |
queries[i].action(); | |
break; | |
} | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment