2010-01-22 5 views
1

나는 단지 downloaded Firefox 3.6 today이고 새로운 기능 목록에는 노트북/컴퓨터가 기울어 진 방향을 감지 할 수있는 an Orientation API이 있습니다. 이것은 분명히 어떤 종류의 하드웨어 기능입니다. 따라서 hardware을 가지고 있지 않다면 프로젝트를 테스트 할 수 있도록 시뮬레이션하는 방법이 있습니까?Firefox 3.6에서 가속도계 이벤트 기능을 시뮬레이션 하시겠습니까?

답변

3

당신은 (Mozilla Orientation Demo 2에서 차용 코드) 다음 코드로 MozTransform을 시뮬레이션 할 수 있어야한다 : 다음과 같이

당신이 방향 API를 기반으로하는 응용 프로그램을 빌드하는 경우
var x = 0; 
var y = 0; 

// This will rotate/zoom your document based on the x and y values: 

document.body.style.MozTransform = 'rotate(' + (-y * 30) + 'deg) ' + 
            'scale(' + (x + 1) + "," + (x + 1) + ')'; 

, 당신이 당신의 이벤트 리스너를 구현할 수 :

function onChangeOrientation(e) 
{ 
    var x = e.x; 
    var y = e.y; 
    var z = e.z; 

    // Here you may need to standardize the values of x, y and z 
    // For example: (-1 * y) on MacBookPro > 5.1. 

    processOrientationLogic(x, y, z); 
} 

// Add the Event Listener for the Accelerometer 
window.addEventListener("MozOrientation", onChangeOrientation, true); 

그런 다음 단순히 X, Y 및 Z 값 processOrientationLogic()를 시작, 방향 이벤트를 시뮬레이션합니다. Firebug에서이 작업을 수행 할 수도 있고, 모든 변경 사항에 대해이 함수를 호출하는 페이지에서 세 가지 슬라이더 컨트롤을 만들 수도 있습니다.

관련 문제