判断当前横竖屏:
if ( window.orientation == 180 || window.orientation==0 ) {
alert("竖屏");
} else if( window.orientation == 90 || window.orientation == -90 ) {
alert("横屏");
}
监听横竖屏切换:
window.addEventListener('orientationchange', function(event) {
if ( window.orientation == 180 || window.orientation==0 ) {
alert("竖屏");
} else if( window.orientation == 90 || window.orientation == -90 ) {
alert("横屏");
}
});