views:

217

answers:

2

I just downloaded Firefox 3.6 today and I noticed in the list of new features they have an Orientation API that can detect the direction that your laptop/computer is tilted. This is clearly a hardware feature of some sort; So if you don't have the hardware to do so is there any way of simulating it so that you can test it out on your projects?

+2  A: 

You should be able to simulate the MozTransform with the following code (code borrowed from Mozilla Orientation Demo 2):

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)  + ')';

If you are building an application based on the Orientation API, you could implement your event listener as follows:

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);

Then to simulate the orientation event, simply launch processOrientationLogic() with your x, y and z values. You could do this from Firebug, or you can also create some sort of three-slider-control on your page that calls this function on every change.

Daniel Vassallo
+1  A: 

look on my example

sakrist