Detecting initial device orientation on iOS in Saf

2019-05-15 06:01发布

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条回答
Ridiculous、
2楼-- · 2019-05-15 06:33

You can check window.orientation on page load.

查看更多
登录 后发表回答