Created
March 9, 2013 23:01
-
-
Save edfuh/5126168 to your computer and use it in GitHub Desktop.
simple countdown timer for some stuff
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
function Countdown(seconds, update, done) { | |
this.length = seconds; | |
this.update = update; | |
this.done = done; | |
} | |
Countdown.prototype.start = function () { | |
var self = this; | |
self.update(self.length); | |
this.timer = setInterval(function () { | |
if (--self.length < 1) { | |
clearInterval(self.timer); | |
self.update(self.length); | |
self.done(); | |
} else { | |
self.update(self.length); | |
} | |
}, 1e3); | |
} | |
Countdown.toClock = function (time) { | |
return ('0' + Math.floor(time / 60)).slice(-2) + ':' + ('0' + time % 60).slice(-2) | |
} | |
document.getElementsByTagName('button')[0].onclick = function () { | |
(new Countdown(64, function(time) { | |
timer.innerHTML = Countdown.toClock(time); | |
}, function() { | |
timer.innerHTML += 'go'; | |
})).start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment