2010-01-22 17 views

回答

3

你應該可以用下面的代碼(代碼Mozilla Orientation Demo 2借來的)模擬MozTransform

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

如果您是基於定位的API構建的應用程序,你可以實現你的事件監聽器如下:

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

然後模擬定位時,只需啓動processOrientationLogic()你的X,Y和Z值。你可以從Firebug這樣做,或者你也可以在頁面上創建某種三滑塊控件,在每次更改時調用此函數。