From d12cfac822a7cae5bfa78b1bc43681bdeb1d5a41 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 20 Jul 2019 19:09:12 +0200 Subject: [PATCH 1/2] test --- src/util/animate.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/util/animate.js b/src/util/animate.js index e4de1f28c7f..3a150cc6248 100644 --- a/src/util/animate.js +++ b/src/util/animate.js @@ -38,24 +38,26 @@ (function tick(ticktime) { // TODO: move abort call after calculation // and pass (current,valuePerc, timePerc) as arguments - if (abort()) { - onComplete(endValue, 1, 1); - return; - } time = ticktime || +new Date(); var currentTime = time > finish ? duration : (time - start), timePerc = currentTime / duration, current = easing(currentTime, startValue, byValue, duration), valuePerc = Math.abs((current - startValue) / byValue); - onChange(current, valuePerc, timePerc); + if (abort()) { + onComplete(endValue, 1, 1); + return; + } if (time > finish) { - options.onComplete && options.onComplete(); + onChange(endValue, 1, 1); + options.onComplete && options.onComplete(endValue, 1, 1); return; } - requestAnimFrame(tick); + else { + onChange(current, valuePerc, timePerc); + requestAnimFrame(tick); + } })(start); }); - } var _requestAnimFrame = fabric.window.requestAnimationFrame || From 380695b8f82ba12c4a385df5a1ff13c3e691a4dd Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 21 Jul 2019 00:49:23 +0200 Subject: [PATCH 2/2] just styling change --- src/util/animate.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/animate.js b/src/util/animate.js index 3a150cc6248..990305f06be 100644 --- a/src/util/animate.js +++ b/src/util/animate.js @@ -4,6 +4,10 @@ return false; } + function defaultEasing(t, b, c, d) { + return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; + } + /** * Changes value from one to another within certain period of time, invoking callbacks as value is being changed. * @memberOf fabric.util @@ -28,7 +32,7 @@ onChange = options.onChange || noop, abort = options.abort || noop, onComplete = options.onComplete || noop, - easing = options.easing || function(t, b, c, d) {return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;}, + easing = options.easing || defaultEasing, startValue = 'startValue' in options ? options.startValue : 0, endValue = 'endValue' in options ? options.endValue : 100, byValue = options.byValue || endValue - startValue; @@ -49,7 +53,7 @@ } if (time > finish) { onChange(endValue, 1, 1); - options.onComplete && options.onComplete(endValue, 1, 1); + onComplete(endValue, 1, 1); return; } else {