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

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

问题描述

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

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

我需要在 orientationchange 。但是,该事件在旋转完成之前触发。因此,记录的高度反映了实际方向改变之前的状态。



如何注册一个事件,以便在完成方向更改后捕获元素尺寸?

解决方案

方向变化需要延迟才能获得新的高度和宽度。这在80%的时间内工作。
$ b $ pre $ window.setTimeout(function(){
//在这里插入高度或宽度的逻辑
},200);


I am attaching a listener to the orientationchange event:

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

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?

解决方案

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天全站免登陆