diff options
Diffstat (limited to 'to/js')
| -rw-r--r-- | to/js/countdown.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/to/js/countdown.js b/to/js/countdown.js new file mode 100644 index 0000000..5fc3039 --- /dev/null +++ b/to/js/countdown.js @@ -0,0 +1,25 @@ +function startTimer(duration, display) { + var timer = duration, + minutes, seconds; + setInterval(function () { + minutes = parseInt(timer / 60, 10); + seconds = parseInt(timer % 60, 10); + + // minutes = minutes < 10 ? "0" + minutes : minutes; + seconds = seconds < 10 ? "" + seconds : seconds; // In "" should be 0 + + display.textContent = seconds; + // Original with minutes + // display.textContent = minutes + ":" + seconds; + + if (--timer < 0*60) { + timer = duration; + } + }, 1000); +} + +window.onload = function () { + var fiveMinutes = 4 * 1, // 60 * 5 + display = document.querySelector('#time'); + startTimer(fiveMinutes, display); +}; |