如何在应用程序和我们的网站中禁用方向横向?

时间:2016-10-14 11:46:46

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

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

2 个答案:

答案 0 :(得分: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)">

答案 1 :(得分:0)

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

<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>
相关问题