Skip to content

Instantly share code, notes, and snippets.

@nadeemelahi
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save nadeemelahi/10367539 to your computer and use it in GitHub Desktop.

Select an option

Save nadeemelahi/10367539 to your computer and use it in GitHub Desktop.
count down timer
<p id="whiteTimeLeft"></p>
<button id="start">start</button>
<button id="stop">stop</button>
var secs = 59999;
function decrementTimer() {
var currentMinutes = "0" + Math.floor(secs / 6000);
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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment