【问题标题】:JavaScript orientation change issues in Internet ExplorerInternet Explorer 中的 JavaScript 方向更改问题
【发布时间】:2013-12-17 00:01:24
【问题描述】:

每次移动设备从纵向切换到横向时,我都需要执行一些 JavaScript 逻辑。我正在使用以下检查来完成此操作:

var doOnOrientationChange = function() {
if (window.innerWidth > window.innerHeight) {
// Execute logic for users who are switching to landscape mode
}
};

这适用于所有 iPhone 和 Android 浏览器,但在 Windows Phone 8 上的 IE10 上会失败。有时当 IE10 用户点击输入时,横向模式的逻辑会触发。

为什么 IE10 将此动作感知为用户切换到横向模式?

【问题讨论】:

    标签: javascript internet-explorer mobile


    【解决方案1】:

    在 IE10 中使用 resize 事件而不是 orientationchange。 Windows Phone 8 中没有orientationchange 事件。

    jQuery 代码:

    $(window).on('resize', function () {
        if (window.innerWidth > window.innerHeight) {
            // Execute logic for users who are switching to landscape mode
        }
    });
    

    另外,请阅读此answer 以了解orientationchangeresize 事件如何在 Android 和 iOS 设备中触发。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多