Skip to content

Instantly share code, notes, and snippets.

@marklawlor
Created October 2, 2014 01:31
Show Gist options
  • Save marklawlor/16fb7d2d4ade0f5d6c33 to your computer and use it in GitHub Desktop.
Save marklawlor/16fb7d2d4ade0f5d6c33 to your computer and use it in GitHub Desktop.
orientationchange fires before the window resize event, which is not ideal when you need to resize content for the new viewport dimensions. This fix will allow you to handle orientation changes after the page has resized
window.addEventListener("orientationchange", function() {
var orientationChange = function(evt) {
//Put your code here
if (window.matchMedia("(orientation: landscape)").matches) {
alert("landscape");
}
else {
alert("portrait");
}
window.removeEventListener('resize', orientationChange);
}
window.addEventListener('resize', orientationChange);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment