Detecting initial device orientation on iOS in Safari

末鹿安然 提交于 2019-12-07 13:22:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!