Uncaught TypeError: Cannot read property 'shift' of null
I am receiving this error when using jquery.counterup.js 1.0 and Waypoints - 3.1.1
This is on line 62 of the counterup plugin
I was getting this error as well. The root of the error was because Counter Up wants to use the 2.x version of Waypoints. I just added a pull request that fixes Counter Up to work with 3.x version of Waypoints. Hope this helps!
digsite's PR seemed to have fixed the problem for me. Thanks!
No problem @cvongrim! Happy to help.
Thanks for the PR. I had the same issue. It would be nice if @bfintal reviewed and approved the PRs. No code updates in 2 years. :-(
To solve it just add the following code in line 62:
if (!$this.data('counterup-nums')) {
return;
}
After
var f = function () {
the code will be after update:
// Updates the number until we're done
var f = function () {
if (!$this.data('counterup-nums')) {
return;
}
$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);
}
};
In my fork I merged a bunch of PRs - it's already on bower and NPM. Waypoint 4.0.0-ready ;)
@ebda3is 👍
fix issue with replacing lines 67 - 79 with :
// Updates the number until we're done var f = function() { if ($this.data('counterup-nums', nums).length) { $this.text($this.data('counterup-nums').shift()); } if ($this.data('counterup-nums').length) { setTimeout($this.data('counterup-func'),delay); } else { delete $this.data('counterup-nums'); $this.data('counterup-nums', null); $this.data('counterup-func', null); } };
I have solved the issue checked once and now it is counting properly
var c = function() { if (!$(t.data('counterup-nums'))) { return; } $(t.text(t.data("counterup-nums").shift())); if (t.data("counterup-nums").length) setTimeout(t.data("counterup-func"), r.delay); else { delete t.data("counterup-nums"); t.data("counterup-nums", null); t.data("counterup-func", null) } };
I am using Waypoints - 4.0.1 I am facing the same issue. the counter is not working. Will I need to use lower version waypoints? http://prntscr.com/n4mpgd
Tried all these solutions.
It counted up first time fine.
The second time it failed with same error as mentioned.
None of the solutions solved the problem - if they did not throw an error then they did not count up to the total number I was after.
I found 1 answer, and it works I fixed this by: var $settings = settings; var $originalText = $this.text(); // added this line Changed: var num = $this.text(); to var num = $originalText;
waypoint 4 changed and removed some options, one of them is "triggerOnce" option that has been removed and "waypoint.destroy()" was replaced. So Changed this line: $this.waypoint(counterUpper, { offset: '100%', triggerOnce: true }); to $this.waypoint(counterUpper, { offset: '100%' }); AND add this line this.destroy() after setTimeout($this.data('counterup-func'), $settings.delay);