Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit ff9dd6a

Browse files
committed
Start counter with a different duration and delay by setting data-counterup-time="" and data-counterup-delay=""
1 parent 20207e2 commit ff9dd6a

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Features:
1111

1212
* Auto-detect for integers, floats or formatted numbers
1313
* The plugin will also use the number of decimal places the original number is using.
14+
* Start counter with a different duration and delay by setting `data-counterup-time=""` and `data-counterup-delay=""`
1415
* Lightweight: ~1kb
1516
* Minimal setup
1617

@@ -33,11 +34,16 @@ Usage
3334

3435
**HTML**
3536

37+
With default values from plugin instantiation.
3638
```
3739
<span class="counter">1,234,567.00</span>
3840
<span>$</span><span class="counter">1.99</span>
3941
<span class="counter">12345</span>
4042
```
43+
With values from `data` attribute.
44+
```
45+
<span class="counter" data-counterup-time="1500" data-counterup-delay="30">1,234,567.00</span>
46+
```
4147

4248
**jQuery**
4349

counterup.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "counterup",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"title": "Counter-Up",
55
"description": "A lightweight jQuery plugin that counts up to a targeted number when the number becomes visible.",
66
"keywords": [

demo/demo.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
21
<!doctype html>
3-
42
<html lang="en">
53
<head>
64
<meta charset="utf-8">
7-
85
<title>Counter Up Demo</title>
96
<meta name="description" content="Counter Up - jQuery Plugin Demo">
107
<meta name="author" content="Benjamin Intal">
@@ -33,7 +30,7 @@
3330
span {
3431
font-size: 66px;
3532
color: #555;
36-
margin-bottom: 350px;
33+
margin-bottom: 250px;
3734
display: inline-block;
3835
font-weight: 400;
3936
text-align: center;
@@ -129,6 +126,11 @@ <h3>(Scroll down)</h3>
129126
<span class="counter" style="display: inline-block; width: 32%">1.9583</span>
130127
<span class="counter" style="display: inline-block; width: 32%">12345</span>
131128
</div>
129+
<div>
130+
<span class="counter" data-counterup-time="1000" data-counterup-delay="25" style="display: inline-block; width: 32%">52,147</span>
131+
<span class="counter" data-counterup-time="1500" style="display: inline-block; width: 32%">1.9583</span>
132+
<span class="counter" data-counterup-time="2000" style="display: inline-block; width: 32%">12345</span>
133+
</div>
132134
<div>
133135
<span style="display: inline-block; width: 32%"><span>$</span><span class="counter">43,753</span></span>
134136
<span class="counter" style="display: inline-block; width: 32%">1,734,195.10</span>

jquery.counterup.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*!
2-
* jquery.counterup.js 1.0
2+
* jquery.counterup.js 1.1.0
33
*
44
* Copyright 2013, Benjamin Intal http://gambit.ph @bfintal
55
* Released under the GPL v2 License
66
*
7-
* Date: Nov 26, 2013
7+
* Date: Feb 05, 2016
88
*/
99
(function( $ ){
1010
"use strict";
@@ -21,11 +21,15 @@
2121

2222
// Store the object
2323
var $this = $(this);
24-
var $settings = settings;
24+
25+
var counter = {
26+
time: $(this).data('counterup-time') || settings.time,
27+
delay: $(this).data('counterup-delay') || settings.delay
28+
};
2529

2630
var counterUpper = function() {
2731
var nums = [];
28-
var divisions = $settings.time / $settings.delay;
32+
var divisions = counter.time / counter.delay;
2933
var num = $this.text();
3034
var isComma = /[0-9]+,[0-9]+/.test(num);
3135
num = num.replace(/,/g, '');
@@ -61,7 +65,7 @@
6165
var f = function() {
6266
$this.text($this.data('counterup-nums').shift());
6367
if ($this.data('counterup-nums').length) {
64-
setTimeout($this.data('counterup-func'), $settings.delay);
68+
setTimeout($this.data('counterup-func'), counter.delay);
6569
} else {
6670
delete $this.data('counterup-nums');
6771
$this.data('counterup-nums', null);
@@ -71,7 +75,7 @@
7175
$this.data('counterup-func', f);
7276

7377
// Start the count up
74-
setTimeout($this.data('counterup-func'), $settings.delay);
78+
setTimeout($this.data('counterup-func'), counter.delay);
7579
};
7680

7781
// Perform counts when the element gets into view
@@ -80,4 +84,4 @@
8084

8185
};
8286

83-
})( jQuery );
87+
})( jQuery );

jquery.counterup.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)