方向改变后的移动视口高度 [英] Mobile viewport height after orientation change

查看:23
本文介绍了方向改变后的移动视口高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将侦听器附加到 orientationchange 事件:

I am attaching a listener to the orientationchange event:

window.addEventListener('orientationchange', function () {
    console.log(window.innerHeight);
});

我需要在orientationchange之后获取文档的高度.但是,该事件在轮换完成之前被触发.因此,记录的高度反映了实际方向变化之前的状态.

I need to get the height of the document after the orientationchange. However, the event is triggered before the rotation is complete. Therefore, the recorded height reflects the state before the actual orientation change.

如何注册允许我在方向更改完成后捕获元素尺寸的事件?

How do I register an event that would allow me to capture element dimensions after the orientation change has been completed?

推荐答案

方向更改需要延迟才能适应新的高度和宽度.这在 80% 的情况下都有效.

Orientation change needs a delay to pick up on the new heights and widths. This works 80% of the time.

window.setTimeout(function() {
    //insert logic with height or width calulations here.
}, 200);

这篇关于方向改变后的移动视口高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆