移动端判断是否处于横屏还是竖屏状态

来源:互联网 发布:个人考勤软件 编辑:程序博客网 时间:2024/06/06 07:06
<style>    @media screen and (orientation:portrait) {        /* portrait-specific styles */    }    /* landscape */    @media screen and (orientation:landscape) {        /* landscape-specific styles */    }</style>

<script type="text/javascript">    var mql = window.matchMedia("(orientation: portrait)");    if(mql.matches) {        alert("竖屏");    } else {        alert("横屏");    }    // 添加一个媒体查询改变监听者    mql.addListener(function(m) {        if(m.matches) {            alert("竖屏");        }        else {            alert("横屏");        }    });</script>

0 0
原创粉丝点击