I wrote the code below to check my mobile screen height when I rotate it to Portrait
or Landscape
.
window.addEventListener("orientationchange", function(event) {
rotateScreen();
}, false);
function rotateScreen() {
alert(window.orientation)
alert($(window).height())
}
When I rotate it to Portrait
, I get 0, 294. When I rotate it to Landscape
, I get 90, 419. The figure is reversed, I have tried to wrap it in $(document).ready()
but it does not work.
$(document).ready(function(){
alert($(window).height())
})
It looks like that when I rotate the mobile to Portrait
, I get the height of Landscape
, and when I rotate the mobile to Landscape
, I get the height of Portrait
. Can someone suggest how to fix it?
Thanks