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

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

Open
marcelomgerais opened this issue May 1, 2018 · 1 comment

Comments

@marcelomgerais
Copy link

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!

@dnunes
Copy link

dnunes commented Jun 7, 2018

Crossposting here from #57 (comment) in case anyone finds it through Google and needs the same thing.

First, re-running the counter is kind of a hard question because it requires us to "stop" the looping once the screen scrolls off, so it can restart when it becomes visible again. AFAIK there is no such funcionality on library (Waypoints) Counter Up uses. You could simply run it in a loop forever every 5-secs after it finishes (it would start when the user scrolls and then will keep looping). This is subideal because if the user scrolls again it could be mid-counting and would not start from 0, but is the best you can right now. This change would require a somehow bigger modification to the code (some 6 or 7 lines, maybe). You would need to store the array with the numbers and run the current "shifting" process in a copy of this array, so you can reset the array later to re-run. You would enqueue the restart using the "else" that detects the end of the counting at line 65.

For the second question, currently Counter Up runs a "parseInt" in the data you input and it cannot really understand any complex masks (it accepts commas as thousands separator). But as the code store the pre-calculated data in an array, you can easily pass the number through a masking function before storing it at line 54 with

nums.unshift(MASKING_FUNCTION(newNum, PARAMS_IF_NEEDED));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants