【问题标题】:How to disable orientation Landscape in app and our website? [duplicate]如何在应用程序和我们的网站中禁用方向横向? [复制]
【发布时间】:2017-02-23 20:12:09
【问题描述】:

我想使用 jquery 在我们的应用程序和网站中禁用方向:横向。 所以请帮助我在应用程序和网站中禁用。

【问题讨论】:

  • 显示你的代码。
  • 我不知道任何禁用代码所以我没有代码所以请帮助我..

标签: javascript php jquery jquery-ui jquery-mobile


【解决方案1】:

抱歉,您不能在网页上强制定向,但是当用户处于横向模式时,您可以在内容中显示一些信息。

为此借助媒体查询并检查方向,在横向样式表(style_landscape.css) 中隐藏所有内容并显示一条消息,即您的应用无法在横向上打开,并且用户必须恢复为纵向模式才能继续。

<link rel="stylesheet" type="text/css" href="css/style_landscape.css" media="screen and (orientation: landscape)">
<link rel="stylesheet" type="text/css" href="css/style_portrait.css" media="screen and (orientation: portrait)">

【讨论】:

    【解决方案2】:

    我不确定它是否会起作用,但试试这个

    <head>
    <style type="text/css">
    #landscape{
             position: absolute;
             top: 0px;
             left: 0px;
             background: #000000;
             width: 100%;
             height: 100%;
             display: none; 
             z-index: 20000;
             opacity: 0.9;
             margin:0 auto;
    }
    #landscape div{
    
            color: #FFFFFF;                                  
            opacity: 1;
            top: 50%;
            position: absolute;
            text-align: center;
            display: inline-block;
            width: 100%;
    }
    </style>
    <script>          
          function doOnOrientationChange()
          {
            switch(window.orientation) 
            {  
              case -90:                 
                     document.getElementById("landscape").style.display="block";
                     break;
              case 90:              
                    document.getElementById("landscape").style.display="block";                 
                    break;
             default:                   
                    document.getElementById("landscape").style.display="none";
                    break;                            
            }
          }
    
          //Listen to orientation change
          window.addEventListener('orientationchange', doOnOrientationChange);  
    
        </script>
    </head>
    <body onload="doOnOrientationChange();">
    <div id="landscape"><div>"Rotate Device to Portrait"</div></div>
    </body>
    

    【讨论】:

    • 谢谢你这个代码正在工作。
    • 欢迎您....
    猜你喜欢
    • 1970-01-01
    • 2016-02-08
    • 2014-09-10
    • 2012-02-24
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多