jsシンプルカウントダウン
931 ワード
毎回カウントダウンを使いたくないです.コードを書いて、煩わしいです.ここでメモしてください.ついでにカウントダウンの簡単なロジックも共有します.
もっと簡単なコードがあれば、みんなに共有できます.
正誤:1018-12-12いくつかの文字エラーを修正しました.いくつかの変数を最適化しました.
もっと簡単なコードがあれば、みんなに共有できます.
var method = {
countdownObj: {
timer: null,
changeTime: 0,
},
countdown: function(long, back) {
var that = this;
if (that.countdownObj.timer) {
clearInterval(that.countdownObj.timer);
}
that.countdownObj.changeTime = long;
back(that.countdownObj.changeTime);
that.countdownObj.timer = setInterval(function() {
that.countdownObj.changeTime--;
back(that.countdownObj.changeTime);
if (that.countdownObj.changeTime < 1) {
clearInterval(that.countdownObj.timer);
}
}, 1000);
}
};
method.countdown(60,function(time){
console.log(time);
});
関数の最初の数字は時間の長さ、第二のコールバック関数、フィードバックのtimeは現在の時間です.正誤:1018-12-12いくつかの文字エラーを修正しました.いくつかの変数を最適化しました.