我正在尝试使用 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 有什么想法吗?提前致谢。
最佳答案
尝试使用 'orientationchange' 事件和 $window 服务(不要忘记注入(inject) $window)
在angular.run()函数中,添加如下事件监听器
angular.element($window).bind('orientationchange', function () {
var width = $window.innerWidth;
});
关于javascript - 如何在平板电脑和手机的 Android 设备方向更改时获得正确的窗口宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34228561/