js方式实现:
var orientation;
//页面加载时调用
orient();
//用户变化屏幕方向时调用
$(window).bind( 'orientationchange', function(e){
orient();
});
function orient() {
if (window.orientation == 90 || window.orientation == -90) {
//横屏
orientation = 'landscape';
return false;
}
else if (window.orientation == 0 || window.orientation == 180) {
//竖屏
orientation = 'portrait';
return false;
}
}
媒体查询方式实现:
@media screen and (orientation:portrait) {
//竖屏
}
@media screen and (orientation:landscape) {
//横屏
}