检测屏幕横屏状态

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);

posted @ 2017-06-19 18:06  BlueSky1024  阅读(173)  评论(0编辑  收藏  举报