问题
I know how to detect device orientation change on iOS in Safari, but I cannot fathom out how to detect initial orientation when my page loads.
It is simple to detect if the device is in portrait or landscape mode - just divide window width with window height and compare result with 1. But I don't see a way to tell portrait from flipped and landscape left from landscape right. Is there a way to do it?
(Why do I need it? Because accelerometer data doesn't flip together with screen when a device is turned on its head. The code must therefore know the current orientation to correctly process accelerometer data.)
回答1:
You can check window.orientation on page load.
来源:https://stackoverflow.com/questions/9152103/detecting-initial-device-orientation-on-ios-in-safari