//通过window.orientation来判断设备横竖屏
function checkOrient() {
if (window.orientation == 0 || window.orientation == 180){//竖屏的时候
var screenOrientation = 'portrait';
$(".vertical").addClass("verticalhide");
}
else if (window.orientation == 90 || window.orientation == -90){//横屏的时候
var screenOrientation = 'landscape';
$(".vertical").removeClass("verticalhide");
}
return screenOrientation;
}
// 添加事件监听
addEventListener('load', function(){
checkOrient();
window.onorientationchange = checkOrient;
});
js判断移动设备横屏竖屏
最新推荐文章于 2024-06-19 17:13:15 发布