2016-10-14 30 views

回答

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> 
+0

謝謝你,這個代碼工作。 –

+0

歡迎你.... – Dave

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)"> 
相關問題