Skip to content

Instantly share code, notes, and snippets.

@afeld
Created August 18, 2012 17:23
Show Gist options
  • Save afeld/3388554 to your computer and use it in GitHub Desktop.
Save afeld/3388554 to your computer and use it in GitHub Desktop.
Corsonus countdown
var startTimeInterval = setInterval(function(){
jQuery.getJSON('http://api.corsonus.com/start.json?callback=?', function(data){
var startTime = data.start_time;
if (startTime){
clearInterval(startTimeInterval);
console.log('counting down...');
var countdownInterval = setInterval(function(){
// number of seconds
var remaining = Math.round((startTime - Date.now()) / 1000);
console.log('number of seconds remaining: ' + remaining);
if (remaining <= 0) {
console.log('start!');
clearInterval(countdownInterval);
}
}, 1000);
} else {
console.log('waiting for start time');
}
})
}, 2000); // check every two seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment