今日、Firefox 3.6をダウンロードしたばかりですが、新機能のリストに、ラップトップ/コンピューターが傾いている方向を検出できるOrientation APIがあることに気付きました。これは明らかに何らかのハードウェア機能です。そのためのハードウェアがない場合、プロジェクトでテストできるようにシミュレートする方法はありますか?
1 に答える
3
MozTransform
次のコード(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) + ')';
Orientation 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から実行できます。または、変更のたびにこの関数を呼び出す、ある種の3スライダーコントロールをページに作成することもできます。
于 2010-01-22T01:31:48.243 に答える