に貼り付け:ここ、ポモドーロクロックプロジェクトをビルドてclearInterval機能にアクセスする必要があるが、これは私のコードペンリンクでカプセル化
https://codepen.io/thinkerElwin/pen/gGMvwR?editors=1010
私のコードスニペット:
$(".session").on("click", function() {
pause ? runSession() : (clearInterval(sessionCounting));
function runSession() {
pause = false;
var start = new Date().getTime()/1000;
var endTime = start + parseInt(sessionLength.html() * 60);
function sessionTimer() {
time = new Date().getTime()/1000;
seconds = Math.ceil((endTime - time) % 60); // ceil for less than starting time
minutes = Math.floor((endTime - time)/60);
console.log(Math.ceil(endTime - time));
if (minutes <= 0 && seconds == 0) {
clearInterval(sessionCounting);
alert();
runBreak();
}
if (minutes < 0) {
minutes = 0;
}
if (seconds < 10) {
seconds = '0' + seconds;
}
$("#title").html("Session is Running!");
$("#timer").html(minutes + ':' + seconds);
};
var sessionCounting = setInterval(sessionTimer, 1000);
sessionCounting;
};
function runBreak() {
var start = new Date().getTime()/1000;
var endTime = start + parseInt(breakLength.html() * 60);
function breakTimer() {
time = (new Date().getTime())/1000;
seconds = Math.ceil((endTime - time) % 60); // ceil for less than starting time
minutes = Math.floor((endTime - time)/60);
console.log(Math.ceil(endTime - time));
if (minutes <= 0 && seconds == 0) {
clearInterval(breakCounting);
alertsound();
runSession();
}
if (minutes < 0) {
minutes = 0;
}
if (seconds < 10) {
seconds = '0' + seconds;
}
$("#title").html("Time to take a break~");
$("#timer").html(minutes + ':' + seconds);
};
var breakCounting = setInterval(breakTimer, 1000);
breakCounting;
};
});
});
一時停止=開始時にはtrue
ユーザーが実行中のタイマーをもう一度クリックしたときにタイマーを止める機能を追加したい、今私はこれを使用しています:
pause? runSession():(clearInterval(sessionCounting)、clearInterval(breakCounting)); 、私はこの機能にアクセスする方法を
しかし、私は
consol.log(てclearInterval(sessionCounting))
を使用しているとき、それは未定義示し、失敗しただろうか?