Skip to content

Instantly share code, notes, and snippets.

@nkcmr
Created December 11, 2012 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkcmr/4259104 to your computer and use it in GitHub Desktop.
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.
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