【问题标题】:Problem with device orientation code in Firefox for AndroidFirefox for Android 中的设备方向代码问题
【发布时间】:2015-08-03 17:13:02
【问题描述】:

下面的代码应该是让网页上的地图成为手机侧身时页面上唯一显示的元素,然后在手机转回原来的时候重新添加其他元素纵向。 这适用于 Android 版 Chrome,但不适用于 Android 版 FireFox v39。第一个警报在 FireFox 中触发,所以我知道支持设备方向,但第二个警报在 FireFox 中永远不会触发,所以我的第二个条件有问题。

if (window.DeviceOrientationEvent) {
        alert("supported");
        window.addEventListener('deviceorientation', function (eventData) {
            if (window.orientation == 90 || window.orientation == -90) {
                alert("90 or -90");
                $("#mapTop").css("display", "none");
                $("#mapBottom").css("display", "none");
            }
            else {
                $("#mapTop").css("display", "block");
                $("#mapBottom").css("display", "block");
            }
        });
    }

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    试试这个看看window.orientation是否在FF中有一些值(我不知道,我不能为你测试。下面的代码应该可以工作。)

    if (window.DeviceOrientationEvent) {
        alert("supported");
        window.addEventListener('deviceorientation', function (eventData) {
            alert(window.orientation)
        });
    }
    

    我建议您使用eventData.alphaeventData.betaeventData.gamma 属性来确定此处所述的方向

    https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent

    【讨论】:

      猜你喜欢
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 2011-06-23
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多