Counter-Up icon indicating copy to clipboard operation
Counter-Up copied to clipboard

Prevent start over & initial number not reached

Open ralphbolliger opened this issue 8 years ago • 7 comments

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?

ralphbolliger avatar Jul 14 '15 17:07 ralphbolliger

Sidenote: if I call the script without time and delay values it gets to the number specified in HTML every time.

ralphbolliger avatar Jul 14 '15 17:07 ralphbolliger

Console says...

TypeError: null is not an object (evaluating 't.data("counterup-nums").shift')

... after scrolling back to top and down again.

ralphbolliger avatar Jul 14 '15 17:07 ralphbolliger

I had a very similar issue, but a different error from the console. What I found was that CounterUp 1.0 was incompatible with Waypoints 3.0+ due to changes within Waypoints. I have a pull request that corrects this, and worked for me. Hopefully, it works for you as well!

ravenroc avatar Jul 23 '15 17:07 ravenroc

In my fork I merged a bunch of PRs - it's already on bower and NPM.

This issue should be fixed with Waypoints-4.0.0 support, please check it out and tell me if it works. Thanks!

ciromattia avatar Mar 24 '16 11:03 ciromattia

@ralphbolliger Agreed that it's annoying that the counter loads every time the element is scrolled into view. @ciromattia In your fork did you include a way to only load the counter animation on first scroll, but not again until page reload?

hipchecker avatar Jun 17 '16 21:06 hipchecker

@hipchecker this is already happening AFAIK. Do you have this same issue even with my version?

ciromattia avatar Jun 19 '16 22:06 ciromattia

@ciromattia I moved this conversation to an issue on your fork https://github.com/ciromattia/jquery.counterup/issues/5

hipchecker avatar Jun 21 '16 16:06 hipchecker