Created
October 2, 2014 01:31
-
-
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
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
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