Skip to content

Instantly share code, notes, and snippets.

@bcoe
Created January 10, 2015 06:26
Show Gist options
  • Select an option

  • Save bcoe/4a43e7916b5c3cd3e108 to your computer and use it in GitHub Desktop.

Select an option

Save bcoe/4a43e7916b5c3cd3e108 to your computer and use it in GitHub Desktop.
countdown.js
$(document).ready(function() {
var components = {
days: {length: 86400000},
hours: {length: 3600000},
minutes: {length: 60000},
seconds: {length: 1000}
},
dateOfWedding = new Date('Fri Oct 23 2015 16:30:00 GMT-0800 (PST)');
Object.keys(components).forEach(function(key) {
components[key].element = $('#countdown .' + key)
});
setInterval(function() {
var now = new Date(),
diff = Math.max(dateOfWedding - now, 0);
Object.keys(components).forEach(function(key) {
var component = components[key],
length = parseInt(diff / component.length);
component.element.text(parseInt(diff / component.length));
diff -= length * component.length;
});
}, 500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment