【问题标题】:Android detect rotation & screen widthAndroid检测旋转和屏幕宽度
【发布时间】:2011-10-13 11:59:29
【问题描述】:

我正在尝试在我的 Motorola Droid 1 上检测 Webkit 中的屏幕旋转。我有以下 JavasCript 代码:

var supportsOrientationChange = "onorientationchange" in window,
    orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";

window.addEventListener(orientationEvent, function() {
    alert("screen.width: " + screen.width + ", window.orientation: " + window.orientation);
}, false);

问题是:当手机纵向旋转时它会提示 screen.width 569,当手机横向旋转时会提示 320。这对我没有任何意义!有人可以澄清一下吗?

谢谢, 伊戈尔

【问题讨论】:

    标签: android webkit rotation landscape portrait


    【解决方案1】:

    我敢打赌,您运行的是 Android 2.2。浏览器报告宽度和高度存在错误。对于初学者,请参阅 screen.width + androidShouldn't window.screen.width/height correspond to actual screen width/height?

    我希望我能提供比第一篇文章中的setTimeout() 解决方法更好的东西,但这可能是你能做的最好的。 (我很想弄错,所以如果有人知道更好的解决方案,请分享!)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 2017-06-06
      相关资源
      最近更新 更多