js获取手机是否横竖屏


https://blog.csdn.net/luyundesign/article/details/115698381

// 检测横竖屏
var orient = ''
function checkOrient() {
    if (window.orientation == 0 ){
        orient = 'portrait 0 right';
    } else if (window.orientation == 180){
        orient = 'portrait 180 left';
    } else if (window.orientation == 90 || window.orientation == -90){
        orient = 'landscape';
    }
}
// 添加事件监听
window.addEventListener('load', function () {
    checkOrient()
    alert(orient)
})
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() {
    checkOrient()
    alert(orient)
})




Loading Disqus comments...
Table of Contents