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

Commit

Permalink
Merge PR bfintal#27
Browse files Browse the repository at this point in the history
  • Loading branch information
ciromattia committed Mar 24, 2016
2 parents 094db62 + ff9dd6a commit 245a1bc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Features:

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

Expand Down Expand Up @@ -44,11 +45,16 @@ CDN provided by [jsDelivr CDN](http://www.jsdelivr.com/#!jquery.counterup)

**HTML**

With default values from plugin instantiation.
```
<span class="counter">1,234,567.00</span>
<span>$</span><span class="counter">1.99</span>
<span class="counter">12345</span>
```
With values from `data` attribute.
```
<span class="counter" data-counterup-time="1500" data-counterup-delay="30">1,234,567.00</span>
```

**jQuery**

Expand Down
2 changes: 1 addition & 1 deletion counterup.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "counterup",
"version": "1.0.0",
"version": "1.1.0",
"title": "Counter-Up",
"description": "A lightweight jQuery plugin that counts up to a targeted number when the number becomes visible.",
"keywords": [
Expand Down
10 changes: 6 additions & 4 deletions demo/demo.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

<!doctype html>

<html lang="en">
<head>
<meta charset="utf-8">

<title>Counter Up Demo</title>
<meta name="description" content="Counter Up - jQuery Plugin Demo">
<meta name="author" content="Benjamin Intal">
Expand Down Expand Up @@ -33,7 +30,7 @@
span {
font-size: 33px;
color: #555;
margin-bottom: 350px;
margin-bottom: 250px;
display: inline-block;
font-weight: 400;
text-align: center;
Expand Down Expand Up @@ -129,6 +126,11 @@ <h3>(Scroll down)</h3>
<span class="counter" style="display: inline-block; width: 32%">1.9583</span>
<span class="counter" style="display: inline-block; width: 32%">12345</span>
</div>
<div>
<span class="counter" data-counterup-time="1000" data-counterup-delay="25" style="display: inline-block; width: 32%">52,147</span>
<span class="counter" data-counterup-time="1500" style="display: inline-block; width: 32%">1.9583</span>
<span class="counter" data-counterup-time="2000" style="display: inline-block; width: 32%">12345</span>
</div>
<div>
<span style="display: inline-block; width: 32%"><span>$</span><span class="counter">43,753</span></span>
<span class="counter" style="display: inline-block; width: 32%">1,734,195.10</span>
Expand Down
16 changes: 10 additions & 6 deletions jquery.counterup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*!
* jquery.counterup.js 1.0
* jquery.counterup.js 1.1.0
*
* Copyright 2013, Benjamin Intal http://gambit.ph @bfintal
* Released under the GPL v2 License
*
* Date: Nov 26, 2013
* Date: Feb 05, 2016
*/
(function( $ ){
"use strict";
Expand All @@ -22,11 +22,15 @@

// Store the object
var $this = $(this);
var $settings = settings;

var counter = {
time: $(this).data('counterup-time') || settings.time,
delay: $(this).data('counterup-delay') || settings.delay
};

var counterUpper = function() {
var nums = [];
var divisions = $settings.time / $settings.delay;
var divisions = counter.time / counter.delay;
var num = $this.text();
var isComma = /[0-9]+,[0-9]+/.test(num);
num = num.replace(/,/g, '');
Expand Down Expand Up @@ -84,7 +88,7 @@
var f = function() {
$this.text($this.data('counterup-nums').shift());
if ($this.data('counterup-nums').length) {
setTimeout($this.data('counterup-func'), $settings.delay);
setTimeout($this.data('counterup-func'), counter.delay);
} else {
delete $this.data('counterup-nums');
$this.data('counterup-nums', null);
Expand All @@ -95,7 +99,7 @@
$this.data('counterup-func', f);

// Start the count up
setTimeout($this.data('counterup-func'), $settings.delay);
setTimeout($this.data('counterup-func'), counter.delay);
};

// Perform counts when the element gets into view
Expand Down
7 changes: 6 additions & 1 deletion jquery.counterup.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 245a1bc

Please sign in to comment.