forked from inorganik/countUp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
countUp-jquery.js
39 lines (29 loc) · 933 Bytes
/
countUp-jquery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(function($) {
$.fn.countup = function(params) {
// make sure dependency is present
if (typeof CountUp !== 'function') {
console.error('countUp.js is a required dependency of countUp-jquery.js.');
return;
}
var defaults = {
startVal: 0,
decimals: 0,
duration: 2,
};
if (typeof params === 'number') {
defaults.endVal = params;
}
else if (typeof params === 'object') {
$.extend(defaults, params);
}
else {
console.error('countUp-jquery requires its argument to be either an object or number');
return;
}
this.each(function(i, elem) {
var countUp = new CountUp(elem, defaults.startVal, defaults.endVal, defaults.decimals, defaults.duration, defaults.options);
countUp.start();
});
return this;
};
}(jQuery));