diff --git a/demo/demo.html b/demo/demo.html index dc32556..d37b1c5 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -93,7 +93,8 @@ jQuery(document).ready(function( $ ) { $('.counter').counterUp({ delay: 10, - time: 1000 + time: 1000, + callback: function(e) { console.log(e); } }); }); @@ -157,4 +158,4 @@

(Scroll down)

- \ No newline at end of file + diff --git a/jquery.counterup.js b/jquery.counterup.js index bc7871f..85e90b6 100644 --- a/jquery.counterup.js +++ b/jquery.counterup.js @@ -14,7 +14,8 @@ // Defaults var settings = $.extend({ 'time': 400, - 'delay': 10 + 'delay': 10, + 'callback': function() {} }, options); return this.each(function(){ @@ -66,6 +67,7 @@ delete $this.data('counterup-nums'); $this.data('counterup-nums', null); $this.data('counterup-func', null); + $settings.callback($this); } }; $this.data('counterup-func', f); @@ -80,4 +82,4 @@ }; -})( jQuery ); \ No newline at end of file +})( jQuery ); diff --git a/jquery.counterup.min.js b/jquery.counterup.min.js index cddf5a1..dc40129 100644 --- a/jquery.counterup.min.js +++ b/jquery.counterup.min.js @@ -5,4 +5,4 @@ * Released under the GPL v2 License * * Date: Nov 26, 2013 -*/(function(e){"use strict";e.fn.counterUp=function(t){var n=e.extend({time:400,delay:10},t);return this.each(function(){var t=e(this),r=n,i=function(){var e=[],n=r.time/r.delay,i=t.text(),s=/[0-9]+,[0-9]+/.test(i);i=i.replace(/,/g,"");var o=/^[0-9]+$/.test(i),u=/^[0-9]+\.[0-9]+$/.test(i),a=u?(i.split(".")[1]||[]).length:0;for(var f=n;f>=1;f--){var l=parseInt(i/n*f);u&&(l=parseFloat(i/n*f).toFixed(a));if(s)while(/(\d+)(\d{3})/.test(l.toString()))l=l.toString().replace(/(\d+)(\d{3})/,"$1,$2");e.unshift(l)}t.data("counterup-nums",e);t.text("0");var c=function(){t.text(t.data("counterup-nums").shift());if(t.data("counterup-nums").length)setTimeout(t.data("counterup-func"),r.delay);else{delete t.data("counterup-nums");t.data("counterup-nums",null);t.data("counterup-func",null)}};t.data("counterup-func",c);setTimeout(t.data("counterup-func"),r.delay)};t.waypoint(i,{offset:"100%",triggerOnce:!0})})}})(jQuery); \ No newline at end of file +*/!function(t){"use strict";t.fn.counterUp=function(e){var n=t.extend({time:400,delay:10,callback:function(){}},e);return this.each(function(){var e=t(this),u=n,a=function(){var t=[],n=u.time/u.delay,a=e.text(),r=/[0-9]+,[0-9]+/.test(a);a=a.replace(/,/g,"");for(var c=(/^[0-9]+$/.test(a),/^[0-9]+\.[0-9]+$/.test(a)),o=c?(a.split(".")[1]||[]).length:0,i=n;i>=1;i--){var s=parseInt(a/n*i);if(c&&(s=parseFloat(a/n*i).toFixed(o)),r)for(;/(\d+)(\d{3})/.test(s.toString());)s=s.toString().replace(/(\d+)(\d{3})/,"$1,$2");t.unshift(s)}e.data("counterup-nums",t),e.text("0");var d=function(){e.text(e.data("counterup-nums").shift()),e.data("counterup-nums").length?setTimeout(e.data("counterup-func"),u.delay):(delete e.data("counterup-nums"),e.data("counterup-nums",null),e.data("counterup-func",null),u.callback(e))};e.data("counterup-func",d),setTimeout(e.data("counterup-func"),u.delay)};e.waypoint(a,{offset:"100%",triggerOnce:!0})})}}(jQuery);