用JavaScript判斷橫屏豎屏問題。JavaScript代碼如下【轉】


/判斷手機橫豎屏狀態:  
function hengshuping(){  
  if(window.orientation==180||window.orientation==0){  
        alert("豎屏狀態!")         
   }  
if(window.orientation==90||window.orientation==-90){  
        alert("橫屏狀態!")          
    }  
 }  
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, false);  
  
//移動端的瀏覽器一般都支持window.orientation這個參數,通過這個參數可以判斷出手機是處在橫屏還是豎屏狀態。  
從而根據實際需求而執行相應的程序。通過添加監聽事件onorientationchange,進行執行就可以了。  

  http://blog.csdn.net/lee_magnum/article/details/17429613


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM