Skip to content

Instantly share code, notes, and snippets.

@meigesir
Last active August 29, 2015 14:11
Show Gist options
  • Save meigesir/7afe3b610b3c92b7e3cf to your computer and use it in GitHub Desktop.
Save meigesir/7afe3b610b3c92b7e3cf to your computer and use it in GitHub Desktop.
简单的检测移动设备横屏、竖屏
/**判断是否是横屏:true-是,false-否**/
function isHorizonScreen(){
var orientation = window.orientation;
// 横屏
if(orientation == 90 || orientation == -90){
return true;
}else{
false;
}
}
// 检测屏幕翻转事件
var evt = "onorientationchange" in window ? "orientationchange" : "resize";
window.addEventListener(evt, function () {
if(isHorizonScreen()){
// 横屏
...
}else{
// 竖屏
...
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment