-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery-countup.js
48 lines (42 loc) · 1.29 KB
/
jquery-countup.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
40
41
42
43
44
45
46
47
48
/* CountUp jQuery Plugin */
// Inspired by http://stackoverflow.com/questions/2540277/jquery-counter-to-count-up-to-a-target-number
// Using jQuery plugin tempate from https://github.com/jquery-boilerplate/boilerplate/
;(function ( $, window, document, undefined ) {
var pluginName = "countUp",
defaults = {
duration: 1500,
easing: 'swing'
};
function Plugin ( element, options ) {
this.element = element;
this.settings = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function () {
var $el = $(this.element);
this.animateCount( $el );
},
animateCount: function ( $el ) {
var num = $el.text();
$el.animate({ countNum: num }, {
duration: this.settings.duration,
easing: this.settings.easing,
step: function() {
$el.text(Math.ceil( this.countNum ));
}
});
}
};
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[ pluginName ] = function ( options ) {
return this.each(function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
}
});
};
})( jQuery, window, document );