網頁

2015年12月13日 星期日

[APP] PhoneGap 螢幕翻轉(Orientation)

Ref: Cordova Plugin Screen Orientation
安裝方式請參閱連結

  1. Android
    window.isPortraitComplete = null; //螢幕轉向完成
           window.isPageReady = null; //網頁讀取(初始值)完成
           window.ScreenWidth = 0;
           window.ScreenHeight = 0;
           document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady()
           {
                 screen.lockOrientation('portrait');
                 window.isPortraitComplete = true;
           }
    isScreenReady();
    function isScreenReady() {
                 //判斷手機處於直立狀態innerWidth/Height網頁目前寬/
                 if( window.innerWidth<window.innerHeight ){
                       if ( window.isPortraitComplete!=null && window.isPageReady!=null && window.isPortraitComplete==true && window.isPageReady==true ) {
                              window.ScreenWidth = window.innerWidth;
                              window.ScreenHeight = window.innerHeight;
                              //螢幕完成轉向之後要執行的動作
                       }
                       else{
                              window.setTimeout("isScreenReady();",200);
                       }
                 }
                 else {
                       window.setTimeout("isScreenReady();",200);
                 }
           }

    $(document).ready(function (){
                 window.isPageReady = true;
    }
  2. iOS
    與Android相同

沒有留言:

張貼留言