首页 > 代码库 > 检测屏幕横屏状态

检测屏幕横屏状态

window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() {
    if (window.orientation === 180 || window.orientation === 0) {
      document.getElementsByTagName("html")[0].style.fontSize=document.documentElement.offsetWidth*12/375+"px"
    }
    if (window.orientation === 90 || window.orientation === -90 ){
      document.getElementsByTagName("html")[0].style.fontSize=document.documentElement.offsetWidth*12/375+"px"
    }
}, false);

检测屏幕横屏状态