-
-
Save colormono/5883963 to your computer and use it in GitHub Desktop.
This file contains 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
var countDown = function (endDate, el) { | |
el = el || $('body'); | |
var leadingZero = function (nb) { | |
return (nb < 10) ? "0" + nb : + nb; | |
}; | |
var updateTimer = function (seconds) { | |
var days = Math.floor(seconds / 86400); | |
seconds -= days * 86400; | |
var hours = Math.floor(seconds / 3600); | |
seconds -= hours * (3600); | |
var minutes = Math.floor(seconds / 60); | |
seconds -= minutes * (60); | |
//return ((days > 0) ? days + " days " : "") + leadingZero(hours) + ":" + leadingZero(minutes) + ":" + leadingZero(seconds); | |
return ((days > 0) ? days + " days" : ""); | |
}; | |
var tick = function () { | |
// Get seconds | |
var nbSeconds = parseInt((+endDate - +new Date) / 1000); | |
if (nbSeconds < 1) { | |
el.html('Time finished!'); | |
return; | |
} | |
el.html(updateTimer(nbSeconds)); | |
setTimeout(tick, 500); | |
}; | |
tick(); | |
}; | |
countDown(new Date('2013-01-17T02:00:00'), $('#countdown')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment