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

Support Exponential Counter #35

Open
abibell opened this issue Jun 29, 2016 · 5 comments
Open

Support Exponential Counter #35

abibell opened this issue Jun 29, 2016 · 5 comments

Comments

@abibell
Copy link

abibell commented Jun 29, 2016

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

@luckydonald
Copy link

Maybe a custom countCallback(int) -> int?

@weisk
Copy link

weisk commented Feb 6, 2017

Unfortunately callback is only called at the end. For something like this, we would need to provide a custom delay function, which can be tweaked to some easing formula with the parameter divisions.

@weisk
Copy link

weisk commented Feb 6, 2017

I've made simple tweaks to the library to allow easing functions, here is an example:

jquery.counterup.js

...
var step = 0;
var easing = 'easeInOutQuint';
var f = function () {
  step++;
  var progress = step / divisions
  var delay = easings[easing](progress);
  delay = parseFloat(delay.toFixed(2));
  delay = delay * 20; // tends to 20 ms
  ...
  if ($this.data('counterup-nums').length) {
    setTimeout($this.data('counterup-func'), delay);
  }
...

where easings is any of the jquery easings formulas, or even your own
https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js

@weisk weisk mentioned this issue Feb 6, 2017
@luckydonald
Copy link

@weisk so i need jquery easings as a dependency now? Or can I just declare my own?

@weisk
Copy link

weisk commented Feb 12, 2017

@luckydonald you don't really need it as a dependency, open the file, and grab the formula for the easing you want

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

3 participants