方向更改后,Javascript获取移动屏幕的宽度 [英] Javascript get mobile screen width after orientation change
本文介绍了方向更改后,Javascript获取移动屏幕的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在捕获这样的orientationchange
事件:
I am capturing the orientationchange
event like this:
$(window).bind( 'orientationchange', function(e){
});
如何在orientationchage
之后获得新的屏幕宽度和高度(以像素为单位)?
How can I get the new screen width and height in pixels after the orientationchage
?
我已经尝试过screen.width
,但这并没有改变,即使更改方向后,它仍保留为初始宽度.
I have tried screen.width
but this doesn't change, it remains as the initial width, even after orientation change.
推荐答案
$(window).bind( 'orientationchange', function(e){
var ori = window.orientation,
width = (ori==90 || ori==-90) ? screen.height : screen.width;
});
这篇关于方向更改后,Javascript获取移动屏幕的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文