Skip to content

Commit

Permalink
[#3] 時間をデクリメントする機能を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
前原夏樹 committed Aug 23, 2018
1 parent 44b03c4 commit 063b2ef
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/assets/javascripts/timer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var timer;
var counter = 60 * 25
document.addEventListener('DOMContentLoaded', function() {
setSeconds(counter);
document.getElementById('btn').addEventListener('click', function() {
toggleBtnFunction();
})
Expand All @@ -8,20 +11,29 @@ document.addEventListener('DOMContentLoaded', function() {
function toggleBtnFunction() {
var button = document.getElementById('btn');
if(button.value == 'Start' || button.value == 'ReStart') {
startTimer();
button.value = 'Stop';
button.className = 'stop-timer';
startTimer();
} else if(button.value == 'Stop') {
stopTimer();
button.value = 'ReStart';
button.className = 'start-timer';
}
}

function startTimer() {

function startTimer() {
timer = setInterval(function() {
counter--;
setSeconds(counter);
}, 1000)
}

function stopTimer() {
clearInterval(timer);
}

}
function setSeconds(restSeconds) {
var seconds = document.getElementById('seconds')
seconds.textContent = restSeconds;
}

0 comments on commit 063b2ef

Please sign in to comment.