Last active
August 29, 2015 13:58
-
-
Save nadeemelahi/10367539 to your computer and use it in GitHub Desktop.
count down timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p id="whiteTimeLeft"></p> | |
<button id="start">start</button> | |
<button id="stop">stop</button> | |
var secs = 599; | |
function decrementTimer() { | |
var currentMinutes = "0" + Math.floor(secs / 60); | |
var currentSeconds = Math.floor((secs % 60)); | |
if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds; | |
var timeLeft = currentMinutes + ":" + currentSeconds; | |
$("#whiteTimeLeft").text(timeLeft); | |
secs-- | |
} | |
var clearDecrementTimer; | |
$("#start").click(function(){ | |
clearDecrementTimer = setInterval(function(){ | |
decrementTimer() | |
}, 1000); | |
}); | |
$("#stop").click(function(){ | |
clearInterval(clearDecrementTimer); | |
}); | |
=============================================================================================================== | |
<p id="whiteTimeLeft"></p> | |
var decrementTimer = function(secs) { | |
var currentMinutes = "0" + Math.floor(secs / 6000); | |
var currentSeconds = Math.floor((secs%60)); | |
if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds; | |
var timeLeft = currentMinutes + ":" + currentSeconds; | |
console.log(timeLeft); | |
$("#whiteTimeLeft").text(timeLeft); | |
if(secs > 0) setTimeout(function(){decrementTimer(secs-1)},1000); | |
}; | |
decrementTimer(59999); | |
=============================================================================================================== | |
<p id="whiteTimeLeft"></p> | |
var element = document.getElementById("whiteTimeLeft"); | |
var time = new Date(); | |
time.setMinutes(10); | |
time.setSeconds(0); | |
function decrementTimer() { | |
element.innerHTML = time.getMinutes() + ":" + time.getSeconds(); // todo: pad zeroes | |
time.setSeconds(time.getSeconds() - 1); | |
setTimeout(decrementTimer, 1000); | |
} | |
decrementTimer(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment