1
我只是downloaded Firefox 3.6 today,我注意到他們有an Orientation API的新功能列表,可以檢測到您的筆記本電腦/電腦傾斜的方向。這顯然是某種硬件特性;因此,如果您沒有hardware這樣做,是否有任何方法模擬它,以便您可以在項目上進行測試?在Firefox 3.6中模擬加速度計事件功能?
我只是downloaded Firefox 3.6 today,我注意到他們有an Orientation API的新功能列表,可以檢測到您的筆記本電腦/電腦傾斜的方向。這顯然是某種硬件特性;因此,如果您沒有hardware這樣做,是否有任何方法模擬它,以便您可以在項目上進行測試?在Firefox 3.6中模擬加速度計事件功能?
你應該可以用下面的代碼(代碼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這樣做,或者你也可以在頁面上創建某種三滑塊控件,在每次更改時調用此函數。