- 7 Tem 2013
- 8,240
- 4
- 723
Step 1: Renaming The Old
First you need to grab a copy of the original plugin from the linked article above and extract it somewhere on your hard drive. Now you don't want to have a plugin named count down that counts up do you? We have to rename it. Change the names of the assets/countdown folder and the files inside it to countup respectfully. Also remember to change the paths in index.html that refer to these files.
Step 2: Writing The New
Only minor modifications have to be done on the plugin itself. Open assets/countup/jquery.contup.js and do the following edits:
this post is quoted
First you need to grab a copy of the original plugin from the linked article above and extract it somewhere on your hard drive. Now you don't want to have a plugin named count down that counts up do you? We have to rename it. Change the names of the assets/countdown folder and the files inside it to countup respectfully. Also remember to change the paths in index.html that refer to these files.
Step 2: Writing The New
Only minor modifications have to be done on the plugin itself. Open assets/countup/jquery.contup.js and do the following edits:
Kod:
// 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
});
this post is quoted