HTML5 計時器,實現工作與放鬆的平衡 countDownSeconds = 60;
var 句柄= null;
//視窗載入
function onLoadWindow() {
aCanvas = document.getElementById("countdownCanvas");
context = aCanvas.getContext("2d") var canvasText = "按開始...";
var xPos = aCanvas.width / 2;
var yPos = aCanvas.height / 2;
context.font = "12pt 世紀哥德式" ;
context.fillStyle = "#008000;";
context.textAlign = "center";
context.textBaseline = "中";
context.fillText(canvasText, xPos, yPos);
}
函數updateCanvas(theContext, width, height) {
if (countDownSeconds clearInterval(handle);
句柄= null;
clearInterval(handle);
句柄= null;
嘿;時間到了! ");
回傳0;
}
minStr = Math.floor(countDownSeconds / 60);
secStr = countDownSeconds % 60;
if (minStr = "0" minStr;
}
if (secStr secStr = "0" secStr;
}
context.clearRect(0, 0, 寬度, 高度);
context.font = "24pt 世紀哥德式";
context.fillText(minStr " : " secStr, 寬度/ 2, 高度/ 2);
countDownSeconds--;
}
function startWorkCountDown() {
if (handle != null) {
clearInterval(handle);
}
countDownSeconds = document.getElementById("workIntervalInput").value *600"). timeDisplayCanvas = document.getElementById("countdownCanvas");
timeDisplayContext2D = timeDisplayCanvas.getContext("2d");
updateCanvas(timeDisplayContext2D, timeDisplayCanvas.width, timeDisplayCanvas.height);
handle = setInterval(function( ) {
updateCanvas(timeDisplayContext2D, timeDisplayCanvas.width, timeDisplayCanvas.height);
}, 1000);
}
function startRestCountDown( 🎜>clearInterval(handle);
}
countDownSeconds = document.getElementById("restIntervalInput").value * 60;
timeDisplayCanvas = document.getElementById("count3vasy); getContext("2d");
updateCanvas(timeDisplayContext2D, timeDisplayCanvas.width, timeDisplayCanvas.height);
handle = setInterval(function() {
pplayupdateCan.Dupplayupdate)
}, 1000);
}
腳本>
頭>
;
工作與生活平衡計時器
標題>
請選擇工作間隔:
>
分鐘
請選擇休息間隔:
分鐘
這是畫布
休息一下
;
&複製;版權所有
頁腳>