Giter VIP home page Giter VIP logo

counter-up's Introduction

Please use Counter-Up2 instead, Counter Up 2 greatly improves on Counter Up, has no dependencies, lightweight, uses modern code, and more.

Counter-Up

Counter-Up is a jQuery plugin that animates a number from zero (counting up towards it). It supports counting up:

  • integers 12345
  • floats 0.1234
  • formatted numbers 1,234,567.00

Features:

  • Auto-detect for integers, floats or formatted numbers
  • The plugin will also use the number of decimal places the original number is using.
  • Lightweight: ~1kb
  • Minimal setup

Requires waypoints.js

Demo

DEMO

Usage

Include

<script src="http://cdnjs.cloudflare.com/ajax/libs/waypoints/2.0.3/waypoints.min.js"></script>
<script src="jquery.counterup.min.js"></script>

HTML

<span class="counter">1,234,567.00</span>
<span>$</span><span class="counter">1.99</span>
<span class="counter">12345</span>

jQuery

$('.counter').counterUp();

or with extra parameters

$('.counter').counterUp({
    delay: 10,
    time: 1000
});

delay - The delay in milliseconds per number count up

time - The total duration of the count up animation

Social Stuff

Twitter: @bfintal & @gambitph

Google+: +Benjamin Intal

counter-up's People

Contributors

bfintal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

counter-up's Issues

Uncaught TypeError: Cannot read property 'replace' of undefined

While integrating counter up with my project I am getting this error on console

Uncaught TypeError: Cannot read property 'replace' of undefined
    at Waypoint.a [as callback] (jquery.counterup.min.js:9)
    at Waypoint.trigger (jquery.waypoints.min.js:59)
    at Group.flushTriggers (jquery.waypoints.min.js:531)
    at jquery.waypoints.min.js:438

Here is my html

<div class="value white">
	<p class="sbold addr-font-h1" ><span class="counter"> 1000 </span></p>
	<p>NEW Records</p>
</div>

here is jquery

<script type="text/javascript">
	$(document).ready(function() {
		$('.counter').counterUp();
	});
</script>

I ahve included script like below,

<!-- Counterup  -->
<script src="assets/vendor/counterup/jquery.waypoints.min.js"></script>
<script src="assets/vendor/counterup/jquery.counterup.min.js"></script>

how to stop repeating

Hi how can we stop its repeating once in counts and it again count the number and decrease the number every time

it's bugging and stopping the site

The problem exists on the mainpage, but the client needs it to be hidden from public view so I moved it here:
https://www.reseaualimentaire.com/open1

I tried to specify the type size but it's not changing it. And the counter is also weird. It used to count right up to the number in a few secs even if it was a huge number but now it takes forever, and won't count all the counters at the same time. (So it takes forever to do the first large number, while everything else stays "0".

It worked fine long after we updated wordpress to 4.8.1

Today all I did was switch the positions of the counters and it started fucking up. Even if I create a new one, on a separate page (so I know there are no weird classes settings etc. affecting it)

Counter up work in Mozilla 19 ?

Hello.

I use this library in Mozilla version 19.

I need know to that browser this library works. Some document about this ?

thanks in advance

Scrolling away from counter then back again gives incorrect final value

I came across a problem with scrolling away from the counter whilst it was still in progress and then scrolling back again

If the original value is 100 and I scrolled away at 50, when I scrolled back it would count from 0 to 50 not 100

I fixed this by:
var $settings = settings;
var $originalText = $this.text(); // added this line

Changed:
var num = $this.text();
to
var num = $originalText;

Number 115

Number 115 is displayed as 114 (delay: 10, time:1000).
Number 115 is displayed as 115 (delay: 10, time:1100).
Where is the problem?

Error on parseInt

When used the number "1,990", the script generates "1,989".
That's why on the list generation of incremental numbers to display, when it calls the operation to preserve as int if input was int, it uses "parseInt": (row 54 : var newNum = Math.round(num / divisions * i);)

(1990 / 100 * 100) = 1989.9999999999998
parseInt(1990 / 100 * 100) = 1989

the script should use instead Math.round
Math.round(1990 / 100 * 100) = 1990

invalid delete operand

I get "invalid delete operand" sometimes.
i deleted this line from jquery.counterup.js to see if it solve issue.
delete $this.data('counterup-nums');

Not Working on Host

Thank You for the Code. Its working on Local Host, But After Publish on Host, It not working. PLZ give Solution
Thank You!

Unable to use span tags elsewhere

When using the plug in, all other uses of the span tag break.
For example I had a bit of code that was simply...
<span class="author">Someones Name</span>

This then when the page renders just displays "NaN".

Prevent start over & initial number not reached

There are two issues on my side:

<span class="counter">600</span>

I call jQuery 2.1.4, Waypoints 3.1.1 and Counterup 1.0 (in that order). Then I call this basic script:

$(document).ready(function() {
    $('.counter').counterUp(time:2000, delay:10);
});

As soon as the .counter element gets into viewport the script starts counting the numbers. Fine.
But when I scroll to the top of the page and scroll down again the counting starts over again (first issue). Annoying but not a problem.
The most weird thing is that the counting script is not getting to the number specified in HTML again. After page refresh it counts up to 600 as specified in HTML. Then I scroll up and down again, it starts to counf again. But it never gets up to 600. It stops at ~400. Doing the scrolling again it gets up to ~200.

Do you have any clue?

Its unusual but it doesnt display 1974

Hi i am wordpress developer and i am struggling to find that why it doesnt display 1974 in the theme..

Other every functionality runs fine and are correct i have done everything to the mark

not work in jquery-3.3.1

if im using "jquery-3.3.1" library it will not work,
but if i am using "jquery.2.2.3" then it will work,
so give me the solution 'How can i use in jquery-3.3.1 ??'

waypoint

waypoint script error "Cannot read property 'left' of undefined"

Initial number not always the final number displayed

Processing number: 1615 results in 1614 after countup.


Config is
$('#track-points:visible').counterUp({
delay: 10,
time: 1000
});


Quick fix is to ensure final number is in the array when it is declared. I.e:

        var num = $this.text();
        var nums = [num];

Alternatively, for loop should be adjusted to make sure the initial number is added.

decelerate

Hi... thanx for your plugin!
there is a way to decelerate the numbers towards the end of the counter...

bye
francesco

Loop the counter on a interval + use "." in separation for more than 1.000.000

Hi, is possible to have the counter in a loop, in time interval. an e.g:
when scroll target to numbers, counter starts, from "0" to " 13.423";
and then, in five seconds (an eg), the counter resumes the count, from 0 to 13.423 again.
its possible? like a 'loop' with interval.

  1. i want to use 1.300.000, but returns "NAn" for me.
    how can i use this format of numbers??

Tks a lot!

Support Exponential Counter

I love this library.

Could we support exponential counting so the numbers look like they are accelerating faster as time goes by giving the user a perception of faster experience?

0, 1, 2, 4, 8, 16, 32... 1024

To do this we would have to replace parseInt(num / divisions * i) with a Math.Log function

Support time format

Hello Benjamin,
First I want to say great job.

Second, in my project, I was asked to introduce hours and time format
So I added a few lines to add your project support times.

Feel free to add to your project
And please DO NOT give me credit for this !!! Because the change is minor and insignificant .

Tnx Oren

(function( $ ){
"use strict";

$.fn.counterUp = function( options ) {

    // Defaults
    var settings = $.extend({
        'time': 400,
        'delay': 10
        }, options);

    return this.each(function(){

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

        var counterUpper = function() {
            var divisions = $settings.time / $settings.delay;
            var num = $this.attr('data-value');
            var nums = [num];
            var isComma = /[0-9]+,[0-9]+/.test(num);
            num = num.replace(/,/g, '');
            var isInt = /^[0-9]+$/.test(num);
            var isFloat = /^[0-9]+\.[0-9]+$/.test(num);
            var isTime = /^[0-9]+\:[0-9]+\:[0-9]+$/.test(num);
            if (isTime) {
                num  = new Date('1970-01-01T' + num + 'Z').getTime() / 1000;  
            }

            var decimalPlaces = isFloat ? (num.split('.')[1] || []).length : 0;

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

                // Preserve as int if input was int
                var newNum = parseInt(num / divisions * i);

                // Preserve float if input was float
                if (isFloat) {
                    newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces);
                }

                // Preserve commas if input had commas
                if (isComma) {
                    while (/(\d+)(\d{3})/.test(newNum.toString())) {
                        newNum = newNum.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
                    }
                }

                // Preserve time if input was in time format 00:01:59
                if (isTime) {
                    newNum = (new Date(newNum * 1000)).toUTCString().match(/(\d\d:\d\d:\d\d)/)[0];
                }

                nums.unshift(newNum);
            }

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

            // Updates the number until we're done
            var f = function() {
                $this.text($this.data('counterup-nums').shift());
                if ($this.data('counterup-nums').length) {
                    setTimeout($this.data('counterup-func'), $settings.delay);
                } else {
                    delete $this.data('counterup-nums');
                    $this.data('counterup-nums', null);
                    $this.data('counterup-func', null);
                }
            };
            $this.data('counterup-func', f);

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

        // Perform counts when the element gets into view
        $this.waypoint(counterUpper, { offset: '100%', triggerOnce: true });
    });

};

})( jQuery );

License

GPL is very very restrictive.

MIT or Apache is good.

I know you are owner and you can choose anything but you want to grow your user make under less restrictive. Pure suggestion :).

Also waypoint is now MIT here is : imakewebthings/waypoints@728ee37

-Yash

Why the value changed after few iterations?

I have this jquery code for re-animating counts every 3 seconds :
$(document).ready(function(){
var countUpLoop = setInterval(countUpNumbers, 3000);
countUpNumbers();

  function countUpNumbers(){        
    $('h1.title').counterUp({
      delay: 100,
      time: 1000
    });
  };

});

HTML:
<h1 class="title" data-bind="title">300</h1>

*After few interations, the counterUp change the original value of 300 to 0.

Change to:
<h1 class="title" data-bind="title">0</h1>

I don't know why, please help to figure it out. Thank you.

Numbers with spaces

Is it possible to add support for numbers with spaces as thousand separator? (e.g. 123 456)

European "." and ","

Can you manage also the european number format (opposite to english) in terms of "." and "," inside numbers? i.e.:

  • "." for > thousand
  • "," for decimal < 1

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.