我有编写的代码:
if ('DeviceMotionEvent' in window) {
deviceMotion = new DeviceMotionEvent("devicemotion", {interval: 20, acceleration:DeviceMotionEventAcceleration});
window.addEventListener("devicemotion", onDeviceMotion, false);
window.dispatchEvent(deviceMotion);
}
function onDeviceMotion(eventData){
accelerationHandler(eventData.acceleration);
intervalHandler(eventData.interval);
}
function accelerationHandler(acceleration) {
document.getElementById("ac_x").innerHTML = acceleration.x.toFixed(precision);
document.getElementById("ac_y").innerHTML = acceleration.y.toFixed(precision);
document.getElementById("ac_z").innerHTML = acceleration.z.toFixed(precision);
}
function intervalHandler(interval) {
document.getElementById("ac_interval").innerHTML = interval;
}
我想将间隔设置为 20,但上面的代码给了我一个默认间隔 16。
我怎样才能正确设置间隔?