//屏幕方向标识,0横屏,其他值竖屏
var orientation=0;
//转屏事件,内部功能可以自定义
function screenOrientationEvent(){
if(orientation == 0)document.getElementById("change").value="竖";
else document.getElementById("change").value="横";
}
var innerWidthTmp = window.innerWidth;
//横竖屏事件监听方法
function screenOrientationListener(){
try{
var iw = window.innerWidth;
//屏幕方向改变处理
if(iw != innerWidthTmp){
if(iw>window.innerHeight)orientation = 90;
else orientation = 0;
//调用转屏事件
// screenOrientationEvent();
if(orientation == 0) {
console.log( "竖");
gaodu();
}else{
console.log( "横");
gaodu();
}
innerWidthTmp = iw;
}
} catch(e){alert(e);};
//间隔固定事件检查是否转屏,默认10毫秒
setTimeout("screenOrientationListener()",100);
}
//启动横竖屏事件监听
screenOrientationListener();
转载于:https://my.oschina.net/u/2542078/blog/607494