//判断手机横竖屏状态:
function hengshuping(){
setTimeout(function(){
if(window.orientation==180||window.orientation==0||window.orientation==90||window.orientation==-90){
var liwc=(($(window).width()));
}
},500);
}
$(window).bind( 'orientationchange', function(e){
hengshuping();
});
function hengshuping(){
setTimeout(function(){
if(window.orientation==180||window.orientation==0||window.orientation==90||window.orientation==-90){
var liwc=(($(window).width()));
}
},500);
}
$(window).bind( 'orientationchange', function(e){
hengshuping();
});
// window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, true);
使用的过程中发现,orientationchange 这个事件,在横竖屏切换的时候会触发,但是是在屏幕切之前触发,导致获取的宽度是上个屏幕状态下的宽度,所以使用延迟方法去获取。