From 07724d9ed5fc4f3ce8369887b3a6179d837b2da7 Mon Sep 17 00:00:00 2001 From: linxu Date: Tue, 21 Mar 2017 21:13:46 +0800 Subject: [PATCH] Repair count up not completed bug --- jquery.counterup.js | 9 ++++++++- jquery.counterup.min.js | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/jquery.counterup.js b/jquery.counterup.js index bc7871f..f8ccf46 100644 --- a/jquery.counterup.js +++ b/jquery.counterup.js @@ -1,10 +1,11 @@ /*! -* jquery.counterup.js 1.0 +* jquery.counterup.js 1.1 * * Copyright 2013, Benjamin Intal http://gambit.ph @bfintal * Released under the GPL v2 License * * Date: Nov 26, 2013 +* Update Date: Mar 21, 2017 */ (function( $ ){ "use strict"; @@ -24,6 +25,12 @@ var $settings = settings; var counterUpper = function() { + //Record original value + if (typeof $this.attr('counterup-text') === 'undefined') + $this.attr('counterup-text', $this.text()); + + if ($this.attr('counterup-text') !== $this.text()) return; //Count up not completed + var nums = []; var divisions = $settings.time / $settings.delay; var num = $this.text(); diff --git a/jquery.counterup.min.js b/jquery.counterup.min.js index cddf5a1..a3fef03 100644 --- a/jquery.counterup.min.js +++ b/jquery.counterup.min.js @@ -1,8 +1,9 @@ /*! -* jquery.counterup.js 1.0 +* jquery.counterup.js 1.1 * * Copyright 2013, Benjamin Intal http://gambit.ph @bfintal * 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 +* Update Date: Mar 21, 2017 +*/(function(a){a.fn.counterUp=function(b){var c=a.extend({"time":400,"delay":10},b);return this.each(function(){var f=a(this);var d=c;var e=function(){if(typeof f.attr("counterup-text")==="undefined"){f.attr("counterup-text",f.text())}if(f.attr("counterup-text")!==f.text()){return}var p=[];var g=d.time/d.delay;var n=f.text();var q=/[0-9]+,[0-9]+/.test(n);n=n.replace(/,/g,"");var l=/^[0-9]+$/.test(n);var h=/^[0-9]+\.[0-9]+$/.test(n);var j=h?(n.split(".")[1]||[]).length:0;for(var m=g;m>=1;m--){var k=parseInt(n/g*m);if(h){k=parseFloat(n/g*m).toFixed(j)}if(q){while(/(\d+)(\d{3})/.test(k.toString())){k=k.toString().replace(/(\d+)(\d{3})/,"$1"+","+"$2")}}p.unshift(k)}f.data("counterup-nums",p);f.text("0");var o=function(){f.text(f.data("counterup-nums").shift());if(f.data("counterup-nums").length){setTimeout(f.data("counterup-func"),d.delay)}else{delete f.data("counterup-nums");f.data("counterup-nums",null);f.data("counterup-func",null)}};f.data("counterup-func",o);setTimeout(f.data("counterup-func"),d.delay)};f.waypoint(e,{offset:"100%",triggerOnce:true})})}})(jQuery); \ No newline at end of file