检测移动震动测量计5秒,然后提醒消息

时间:2016-03-19 10:46:36

标签: javascript php jquery mobile shake

我正在开发一个应用程序,用户可以摇动手机一段时间e,g 5秒,然后摇动事件计算他们的总摇动时间,然后显示警告消息,我正在使用shake.js库,但它会在单次摇动后改变产品,我想计算设备的总振动时间,然后显示一些信息。

请任何人帮我解决这个问题,真的卡在这里。 下面是我到目前为止编写的代码。

function changeProduct() {
    var shirts = [
                  ["images/1.jpg","12.65"],
                  ["images/2.jpg","10.00"],
                  ["images/3.jpg","15.50"],
                  ["images/4.jpg","12.65"],
                  ["images/5.jpg","13.00"],
                  ["images/6.jpg","11.85"]
                  ];

    var pos = Math.floor((Math.random() * shirts.length) + 0);
    $("#image").html($("<img/>").attr("src", shirts[pos][0]));
    $(".price").html("$" + shirts[pos][1]);
}

$(document).ready(function() {
    function onShake() {
        changeProduct();
    }

    $.shake({
        callback: function() {
            onShake();
        }
    });
});

1 个答案:

答案 0 :(得分:0)

你应该在你的函数之外的某个地方有这样的东西来计算它:

var totalShakeTime = 0;

当您显示结果时,在显示之前:

totalShakeTime += currentShakeTime; //where currentShakeTime represents the last value