如何计算使用javascript检测到的抖动数量

How to count the number of shakes detected using javascript

本文关键字:抖动 检测 计算使用 javascript      更新时间:2023-09-26

http://www.ivangabriele.com/cordova-detecting-shaking/

我正在学习用javascript编写shake函数。但我不知道如何检测和统计用户的抖动次数,有人能帮我吗?

    shake.startWatch(onShake);
    function onShake()
    {
      alert('Shook');
    }
    // Stop watching for shaking event
    shake.stopWatch();

这里有一种计算抖动的方法。

shake.startWatch(onShake);
var count = 0;
function onShake()
{
  alert('Shook');
  count++ //increases count by 1 each time the function is called.
}
// Stop watching for shaking event
shake.stopWatch();