简体   繁体   English

旋转设备Google Chrome时显示方向错误

[英]Orientation is shown wrong while rotating device Google chrome

I have a HTML5 page which determines whether the device is "Portrait" mode or in "Landscape" . 我有一个HTML5页面,该页面确定设备是“纵向”模式还是“横向”模式。

Below is the code i have alerted the orientation . 下面是我已通知方向的代码。 Sometimes when i turn from landscape to portrait it still alerts as landscape and the co ordinates i check are shown as wrong . 有时,当我从风景转向肖像时,由于风景和我检查的坐标显示为错误,它仍然会发出警报。 The test device is Google Nexus 测试设备是Google Nexus

Tablet Google Nexus 7 Andriod version 4.2.2 Chrome App version:35.0.1916.141 OS Andriod 4.4.2;Nexus 7 Build/KOT49H Javascript version: V8 3.25.28.18 平板电脑Google Nexus 7 Andriod版本4.2.2 Chrome应用版本:35.0.1916.141 OS Andriod 4.4.2; Nexus 7 Build / KOT49H Javascript版本:V8 3.25.28.18

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <div id="page">

    </div>
</body>
</html>
<script type="text/javascript">
    function pageSetter() {
        if (window.matchMedia("(orientation: portrait)").matches) {
            // you're in PORTRAIT mode
            alert('Portrait');
        }

        if (window.matchMedia("(orientation: landscape)").matches) {
            // you're in LANDSCAPE mode
            alert('LANDSCAPE');
        }
    }
    pageSetter();
    window.addEventListener("orientationchange", function () {
        pageSetter();
    }, false)

</script>

window.orientation ==0 refers to the default orientation . window.orientation == 0表示默认方向。 Doesnt mean it is in portrait mode. 并不意味着它处于纵向模式。 Below link explains in detail. 下面的链接详细说明。

Misconception about Window Orientation 对窗口方向的误解

Solution is to use Resize instead 解决方法是改用“调整大小”

Portrait/Landscape detection 人像/风景检测

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM