ボタンをクリックするたびに、この形式の00:00:00でタイマーを開始するこの関数を取得しました。しかし、関数の再開と一時停止の方法がわかりません。役立つと思われるスニペットをいくつか見つけましたが、それらを機能させることができませんでした。jsでオブジェクトを使用するのは初めてです。
function clock() {
var pauseObj = new Object();
var totalSeconds = 0;
var delay = setInterval(setTime, 1000);
function setTime() {
var ctr;
$(".icon-play").each(function () {
if ($(this).parent().hasClass('hide')) ctr = ($(this).attr('id')).split('_');
});
++totalSeconds;
$("#hour_" + ctr[1]).text(pad(Math.floor(totalSeconds / 3600)));
$("#min_" + ctr[1]).text(pad(Math.floor((totalSeconds / 60) % 60)));
$("#sec_" + ctr[1]).text(pad(parseInt(totalSeconds % 60)));
}
}
pad()は先行ゼロを追加するだけです