The meta tag “viewport” lets me set up the initial scale for a website, but this can get weird if the user then flips the orientation of the device.
For example, if I set the scale to be 800×380 and the user opens the website in portrait mode, this scale is obviously wrong, and when the user rotates 90deg, the website ends up being more like 1650 wide.
How would I set a viewport such that if the device is landscape to begin with, it’s 800×380, and if it’s portrait to begin with, it’s 380×800?
To detect orientation change, attach an event listener to the window:
In the updateOrientation function you can detect which orientation the device is in and reset the viewport attributes accordingly: