zoukankan      html  css  js  c++  java
  • js如何设置网页横屏和竖屏切换

    <!DOCTYPE html>

    <html>
    <head>
    <meta http-equiv="Content-Type" content="application/xhtml+xml;charset=UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <title>手机横、竖屏事件</title>
    <script language="javascript" type="text/javascript">
    //屏幕方向标识,0横屏,其他值竖屏
    var orientation=0;
    //转屏事件,内部功能可以自定义
    function screenOrientationEvent(){
        if(orientation == 0)document.getElementById("change").value="竖";
        else document.getElementById("change").value="横";
    }
    var innerWidthTmp = window.innerWidth;
    //横竖屏事件监听方法
    function screenOrientationListener(){
        try{
            var iw = window.innerWidth;    
            //屏幕方向改变处理
            if(iw != innerWidthTmp){
                if(iw>window.innerHeight)orientation = 90;
                else orientation = 0;
                //调用转屏事件
                screenOrientationEvent();
                innerWidthTmp = iw;
            }
        } catch(e){alert(e);};
        //间隔固定事件检查是否转屏,默认500毫秒
        setTimeout("screenOrientationListener()",500);
    }
    //启动横竖屏事件监听
    screenOrientationListener();
    </script>
    </head>
    <body onload="screenOrientationEvent()">
    <input id="change" type="text" value=""/>
    </body>
    </html>
  • 相关阅读:
    Python-内置数据结构listdictset
    Python-内置结构listsetdicttuple
    Python-内置数据结构
    Python-函数作用域和集合列表字典元祖
    Python-函数参数和文档
    Python-while循环+函数
    Python-分支循环
    Python基础
    五、Jmeter-数据库数据进行参数化
    mysql索引:四种类型,两种方法
  • 原文地址:https://www.cnblogs.com/gxw123/p/13408422.html
Copyright © 2011-2022 走看看