domingo, 15 de diciembre de 2013
jueves, 12 de diciembre de 2013
domingo, 10 de noviembre de 2013
// Creating the plugin
$.fn.countup = function(prop){
var options = $.extend({
callback : function(){},
start : new Date() // Changing this to "start"
},prop);
// Tename the "left" variable to "passed"
var passed = 0, d, h, m, s,
positions;
init(this, options);
positions = this.find('.position');
(function tick(){
// Calculate the passed time
passed = Math.floor((new Date() - options.start) / 1000);
// Calculate the passed minutes, hours and days
d = Math.floor(passed / days);
updateDuo(0, 1, d);
passed -= d*days;
h = Math.floor(passed / hours);
updateDuo(2, 3, h);
passed -= h*hours;
m = Math.floor(passed / minutes);
updateDuo(4, 5, m);
passed -= m*minutes;
// Number of seconds passed
s = passed;
updateDuo(6, 7, s);
// Calling an optional user supplied callback
options.callback(d, h, m, s);
// Scheduling another call of this function in 1s
setTimeout(tick, 1000);
})();
// This function updates two digit positions at once
function updateDuo(minor,major,value){
switchDigit(positions.eq(minor),Math.floor(value/10)%10);
switchDigit(positions.eq(major),value%10);
}
return this;
};
To call the plugin, simply do the following (this is also the code you must place in script.js instead of the current one):
$('#countdown').countup();
Alternatively, if you wish to count up from a moment in the past:
$('#countdown').countup({
start: new Date(2012, 10, 27, 15, 58, 21) //year, month, day, hour, min, sec
});
