Skip to content
This repository has been archived by the owner on Aug 22, 2021. It is now read-only.

Added functionality to specify the number to begin moving up from #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -50,14 +50,17 @@ $('.counter').counterUp();
```
$('.counter').counterUp({
delay: 10,
time: 1000
time: 1000,
beginAt: 0
});
```

`delay` - The delay in milliseconds per number count up

`time` - The total duration of the count up animation

`beginAt` - Where you want the number to begin moving up from

Social Stuff
============

Expand Down
2 changes: 1 addition & 1 deletion demo/demo.html
Expand Up @@ -157,4 +157,4 @@ <h3>(Scroll down)</h3>
<script src="http://cdnjs.cloudflare.com/ajax/libs/waypoints/2.0.3/waypoints.min.js"></script>
<script src="../jquery.counterup.min.js"></script>
</body>
</html>
</html>
11 changes: 6 additions & 5 deletions jquery.counterup.js
Expand Up @@ -14,7 +14,8 @@
// Defaults
var settings = $.extend({
'time': 400,
'delay': 10
'delay': 10,
'beginAt': 0
}, options);

return this.each(function(){
Expand All @@ -32,10 +33,10 @@
var isInt = /^[0-9]+$/.test(num);
var isFloat = /^[0-9]+\.[0-9]+$/.test(num);
var decimalPlaces = isFloat ? (num.split('.')[1] || []).length : 0;
if ($settings.beginAt > num) $settings.beginAt = num

// Generate list of incremental numbers to display
for (var i = divisions; i >= 1; i--) {

for (var i = divisions; i >= $settings.beginAt / num * divisions; i--) {
// Preserve as int if input was int
var newNum = parseInt(num / divisions * i);

Expand All @@ -55,7 +56,7 @@
}

$this.data('counterup-nums', nums);
$this.text('0');
$this.text($settings.beginAt);

// Updates the number until we're done
var f = function() {
Expand All @@ -80,4 +81,4 @@

};

})( jQuery );
})( jQuery );
14 changes: 13 additions & 1 deletion jquery.counterup.min.js
Expand Up @@ -5,4 +5,16 @@
* 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);
*/
!function(t){"use strict"
t.fn.counterUp=function(e){var n=t.extend({time:400,delay:10,beginAt:0},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,"")
var i=(/^[0-9]+$/.test(a),/^[0-9]+\.[0-9]+$/.test(a)),o=i?(a.split(".")[1]||[]).length:0
u.beginAt>a&&(u.beginAt=a)
for(var c=n;c>=u.beginAt/a*n;c--){var s=parseInt(a/n*c)
if(i&&(s=parseFloat(a/n*c).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(u.beginAt)
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))}
e.data("counterup-func",d),setTimeout(e.data("counterup-func"),u.delay)}
e.waypoint(a,{offset:"100%",triggerOnce:!0})})}}(jQuery)