方向更改后的移动视口高度 [英] Mobile viewport height after orientation change
问题描述
我正在将监听器附加到 orientationchange
事件:
window.addEventListener('orientationchange',function(){
console.log(window.innerHeight);
});
我需要在 orientationchange $之后获取文档的高度C $ C>。但是,该事件在旋转完成之前触发。因此,记录的高度反映了实际方向改变之前的状态。
如何注册一个事件,以便在完成方向更改后捕获元素尺寸?
方向变化需要延迟才能获得新的高度和宽度。这在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屋!