fre*_*ent 2 javascript jquery android width orientation-changes
我需要在orientationchange上计算屏幕宽度.
我是这样做的:
$(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);
});
Run Code Online (Sandbox Code Playgroud)
我已经使用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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2730 次 |
| 最近记录: |