如何在Jquery/Javascript中的orientationchange事件上获得Android上的页面宽度?

如何在Jquery/Javascript中的orientationchange事件上获得Android上的页面宽度?,javascript,jquery,android,width,orientation-changes,Javascript,Jquery,Android,Width,Orientation Changes,我需要计算方向改变时的屏幕宽度 我是这样做的: $(window).on('orientationchange', function(event){ $(this).panelWidth("orientationchange") }); panelWidth: function (fromWhere) { window.setTimeout(function () { var $wrapWidth = $('div:jqmData(wrapper="true").

我需要计算方向改变时的屏幕宽度

我是这样做的:

$(window).on('orientationchange', function(event){
   $(this).panelWidth("orientationchange")
   });

panelWidth: function (fromWhere) {
   window.setTimeout(function () {
      var $wrapWidth = $('div:jqmData(wrapper="true").ui-page-active').innerWidth();
      console.log( $wrapWidth );
      },10);
   });
我已经在使用10毫秒的延迟来计算屏幕宽度,但在Android上它仍然不起作用

我的屏幕是320x480。如果我从纵向开始,改为横向,我得到320px。当我改回纵向时,我控制480px,所以宽度似乎总是在方向实际改变之前计算出来的

如果可能的话,我不想增加超时时间。还有什么其他方法可以确保$wrapWidth只在Android完成“旋转”屏幕时计算

谢谢你的帮助

编辑
来自Jquery Mobile sourceode的一些信息:

...as the actual screen resize takes place before or after the orientation 
change event has been fired depending on implementation (eg android 2.3 is 
before, iphone after). More testing is required to determine if a more reliable 
method of determining the new screensize is possible when orientationchange 
is fired. (eg, use media queries + element + opacity)

这是framwork Android设备中的一个bug。你可以做两件事

  • 根据,将超时时间更改为100毫秒。显然,这将解决问题
  • 由于在起始点之前触发的事件已更改,因此对宽度和高度使用相反的值。比如:

    $(窗口).bind('orientationchange',函数(事件){ 如果(event.orientation==“纵向”){ //更改您的页面以获得横向效果 }else if(event.orientation==“横向”){ //将页面更改为纵向 }
    });


  • 啊。我喜欢第二种解决方法。很不错的!谢谢你指出这一点!好啊我得到了一个解决方案,它可以跨设备工作(不仅在Android上)。看到我的答案了吗