2011-10-18 13 views
1
window.onresize = function(){ updateOrientation(e); } 
    function updateOrientation(e) { 
     alert("hey"); 

     deviceWidth = $('body').width(); 
     if (deviceWidth == 320) { 
      currentOrientation = "portrait"; 
     } 
     else if (deviceWidth == 480) { 
      currentOrientation = "landscape"; 
     } 

     // fire a function that checks the orientation every x milliseconds 
     setInterval(checkOrientation, 500); 

     // check orientation 
     function checkOrientation() { 
      deviceWidth = $('body').width(); 
      if (deviceWidth >= '1200') { 
       newOrientation = "portrait"; 
      } 
      else if (deviceWidth <= '900') { 
       newOrientation = "landscape"; 
      } 
      // if orientation changed since last check, fire either the portrait or landscape function 
      if (newOrientation != currentOrientation) { 
       if (newOrientation == "portrait") { 
        changedToPortrait(); 
       } 
       else if (newOrientation == "landscape") { 
        changedToLandscape(); 
       } 
       currentOrientation = newOrientation; 
      } 
     } 

     // landscape stuff 
     function changedToLandscape() { 
      alert('Orientation has changed to Landscape!'); 
     } 

     // portrait stuff 
     function changedToPortrait() { 
      alert('Orientation has changed to Portrait!'); 
     } 
    } 

これは、phonegapを使用してAndroidタブレットの向きの変化を検出するために使用しています。何らかの形でコードが動作していません。助言がありますか?推測の方向変化のイベントを生成することはできません。携帯電話の向きの変更

+0

? – Mkpatel

答えて

0

これは、PhoneGapの中で私の作品:Khushは-ているあなたは、Androidアプリケーションを開発するためのPhoneGapと一緒にjQMフレームワークを使用して、@

function onOrientationChange() { 
    switch (window.orientation) { 
     case -90: 
     case 90: 
      alert('landscape'); 
      break; 
     default: 
      alert('portrait'); 
      break; 
    } 
}; 
window.onresize = onOrientationChange;