【问题标题】:How to get the correct window width on orientation change for android devices both tablets and phone如何在 Android 设备(平板电脑和手机)的方向更改时获得正确的窗口宽度
【发布时间】:2016-03-17 15:54:29
【问题描述】:

我正在尝试使用 jquery 函数 $(window).outerWidth(true); 计算 android 设备在方向更改时的窗口宽度。此计算为 iphone 和 ipad 提供了正确的方向更改宽度,但在 android 中没有。如果我最初以横向模式或纵向模式加载页面,我将获得正确的宽度,但是一旦我在加载页面后更改方向,我将获得纵向模式的宽度,就像在横向模式下一样,反之亦然。请建议正在发生的事情以及我该如何处理这个问题,以便我在 android 设备的方向更改时获得正确的窗口宽度。

我正在尝试通过这篇帖子 How to get the correct window width on orientation change for android devices both tablets and mobiles 解决问题,但任何事情都对我有用。

@user850234 有什么想法吗?提前致谢。

【问题讨论】:

  • 不要使用 JavaScript 窗口对象,而是尝试使用角度 $window 。 docs.angularjs.org/api/ng/service/$window
  • 感谢您的回答,但它不起作用。我有同样的问题。有什么想法吗?

标签: javascript android css cordova ionic


【解决方案1】:

尝试使用 'orientationchange' 事件和 $window 服务(不要忘记注入 $window)

在 angular.run() 函数中,添加如下事件监听器

    angular.element($window).bind('orientationchange', function () {
          var width = $window.innerWidth;  
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 2016-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多