2013-05-16 1 views
0

장치 방향 이벤트를 사용하여 모바일 장치의 머리글을 확인하려고합니다.장치 방향에서 수평 방향 가져 오기

if (window.DeviceOrientationEvent) { 
    window.addEventListener("deviceorientation", handleOrientation, false); 
} 
else{ 
    alert("Device Orientation is not available"); 
} 

내 handleOrientation 기능에서 나는 알파, 베타, 감마을 가질 수 있습니다 이 내가 할 것입니다. 하지만 장치의 제목을 갖고 싶습니다. 당신이 당신의 장치를 내려 놓고 같은 것을 할 때 :

enter image description here

function handleOrientation(orientData) { 

    //var absolute = orientData.absolute; 
    //var alpha = orientData.alpha; 
    //var beta = orientData.beta; 
    //var gamma = orientData.gamma; 
} 

어떻게 위의 값에서 장치의 제목을받을 수 있나요?

닐스

답변

1

당신은 window.orientation를 사용하지만, 관심을 지불 할 수를 : 다른 장치는 서로 다른 값을 반환합니다.

function handleOrientation() { 

    switch(window.orientation) 
    case 0: 
    // do your stuff 
    break; 
    case -90 
     .... 
} 

window.addEventListener('onorientationchange', handleOrientation); 

아이폰 갖는다 : (https://developer.apple.com/library/safari/#documentation/DataManagement/Reference/DOMWindowAdditionsReference/DOMWindowAdditions/DOMWindowAdditions.html부터)

0 => 세로 방향. 이것은 기본값입니다.

-90 => 화면을 시계 방향으로 돌려 가로 방향으로 배치하십시오.

90 => 화면을 반 시계 방향으로 돌려 가로 방향으로 배치하십시오.

180 => 화면의 거꾸로 된 세로 방향입니다. 이 값은 현재 iPhone에서 지원되지 않습니다.