Last active
August 29, 2015 14:11
-
-
Save meigesir/7afe3b610b3c92b7e3cf to your computer and use it in GitHub Desktop.
简单的检测移动设备横屏、竖屏
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**判断是否是横屏: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