I am attaching a listener to the orientationchange
event:
window.addEventListener('orientationchange', function () {
console.log(window.innerHeight);
});
I need to get the height of the document after the orientationchange
. However, the event is triggered before the rotation is complete. Therefore, the recorded height reflects the state before the actual orientation change.
How do I register an event that would allow me to capture element dimensions after the orientation change has been completed?
For people who just want the
innerHeight
of the window object after theorientationchange
there is a simple solution. Usewindow.innerWidth
. TheinnerWidth
during theorientationchange
event is theinnerHeight
after completion of theorientationchange
:I am not sure if 180-degree changes are done in two 90 degree steps or not. Can't simulate that in the browser with the help of developer tools. But If you want to safeguard against a full 180, 270 or 360 rotation possibility it should be possible to use
screen.orientation.angle
to calculate the angle and use the correct height and width. Thescreen.orientation.angle
during the event is the target angle of theorientationchange
event.