Skip to content

Commit e42f0b5

Browse files
committed
fixed issue where calling update in callback caused infinite rAF
1 parent f79e9c1 commit e42f0b5

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

countUp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
4141
}
4242

4343
var self = this;
44-
self.version = function () { return '1.8.4'; };
44+
self.version = function () { return '1.8.5'; };
4545

4646
function formatNumber(num) {
4747
num = num.toFixed(self.decimals);
@@ -204,6 +204,7 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
204204
// pass a new endVal and start animation
205205
self.update = function (newEndVal) {
206206
if (!self.initialize()) return;
207+
if (newEndVal === self.frameVal) return;
207208
cancelAnimationFrame(self.rAF);
208209
self.paused = false;
209210
delete self.startTime;

dist/countUp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
5252
}
5353

5454
var self = this;
55-
self.version = function () { return '1.8.4'; };
55+
self.version = function () { return '1.8.5'; };
5656

5757
function formatNumber(num) {
5858
num = num.toFixed(self.decimals);
@@ -215,6 +215,7 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
215215
// pass a new endVal and start animation
216216
self.update = function (newEndVal) {
217217
if (!self.initialize()) return;
218+
if (newEndVal === self.frameVal) return;
218219
cancelAnimationFrame(self.rAF);
219220
self.paused = false;
220221
delete self.startTime;

dist/countUp.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,11 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
147147

148148
// set CountUp options
149149
// you don't need to do this - you can use the default options
150-
var demo, code, data, stars, easingFunctions,
150+
var demo, options, code, data, stars, easingFunctions,
151151
useOnComplete = false,
152152
useEasing = true,
153153
easingFn = null,
154-
useGrouping = true,
155-
options = {
156-
useEasing : useEasing, // toggle easing
157-
easingFn : easingFn, // defaults to easeOutExpo, but you can specify your own
158-
useGrouping : useGrouping, // 1,000,000 vs 1000000
159-
separator : ',', // character to use as a separator
160-
decimal : '.', // character to use as a decimal
161-
};
154+
useGrouping = true;
162155

163156
window.onload = function() {
164157
// in case we're testing angular
@@ -233,10 +226,10 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
233226
easingFn : typeof easingFn === 'undefined' ? null : easingFn,
234227
useGrouping : useGrouping,
235228
separator : document.getElementById("separator").value,
236-
decimal : document.getElementById("decimal").value,
237-
prefix: prefix,
238-
suffix: suffix
229+
decimal : document.getElementById("decimal").value
239230
};
231+
if (prefix.length) options.prefix = prefix;
232+
if (suffix.length) options.suffix = suffix;
240233

241234
// you don't have to create a new instance of CountUp every time you start an animation,
242235
// you can just change the properties individually. But I do here in case user changes values in demo.
@@ -308,17 +301,15 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
308301
startVal = Number(startVal.replace(',','').replace(' ',''));
309302
var endVal = document.getElementById("endVal").value;
310303
endVal = Number(endVal.replace(',','').replace(' ',''));
311-
var decimals = document.getElementById("decimals").value;
312-
var duration = document.getElementById("duration").value;
313-
var separator = document.getElementById("separator").value;
314-
var decimal = document.getElementById("decimal").value;
315-
var prefix = document.getElementById("prefix").value;
316-
var suffix = document.getElementById("suffix").value;
317-
318-
var easingFn = getEasingFn();
319-
var easingFnBody = getEasingFnBody(easingFn);
320-
321-
var code = '';
304+
var decimals = document.getElementById("decimals").value,
305+
duration = document.getElementById("duration").value,
306+
separator = document.getElementById("separator").value,
307+
decimal = document.getElementById("decimal").value,
308+
prefix = document.getElementById("prefix").value,
309+
suffix = document.getElementById("suffix").value,
310+
easingFn = getEasingFn(),
311+
easingFnBody = getEasingFnBody(easingFn),
312+
code = '';
322313

323314
if (useEasing && easingFn) {
324315
code += 'var easingFn = ';
@@ -335,8 +326,8 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
335326
code += (useGrouping) ? '&emsp;&emsp;useGrouping : true, <br>' : '&emsp;&emsp;useGrouping : false, <br>';
336327
code += '&emsp;&emsp;separator : \''+separator+'\', <br>';
337328
code += '&emsp;&emsp;decimal : \''+decimal+'\', <br>';
338-
code += '&emsp;&emsp;prefix : \''+prefix+'\', <br>';
339-
code += '&emsp;&emsp;suffix : \''+suffix+'\' <br>';
329+
if (prefix.length) code += '&emsp;&emsp;prefix : \''+prefix+'\', <br>';
330+
if (suffix.length) code += '&emsp;&emsp;suffix : \''+suffix+'\' <br>';
340331
code += '};<br>';
341332
code += 'var demo = new CountUp("myTargetElement", '+startVal+', '+endVal+', '+decimals+', '+duration+', options);<br>';
342333
if (useOnComplete) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "countup.js",
33
"description": "Animates a numerical value by counting to it",
4-
"version": "1.8.4",
4+
"version": "1.8.5",
55
"license": "MIT",
66
"main": "./dist/countUp.min.js",
77
"repository": {

0 commit comments

Comments
 (0)