animate-value
Version:
🏃 animates a numeric value
50 lines (43 loc) • 1.67 kB
JavaScript
import tick from './lib/tick';
import calcStartEnd from './lib/calc/calcStartEnd';
export default (function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return new Promise(function (resolve) {
var _options$from = options.from,
from = _options$from === undefined ? 0 : _options$from,
_options$to = options.to,
to = _options$to === undefined ? 1 : _options$to,
_options$easing = options.easing,
easing = _options$easing === undefined ? 'easeInQuad' : _options$easing,
_options$duration = options.duration,
duration = _options$duration === undefined ? 600 : _options$duration,
_options$delay = options.delay,
delay = _options$delay === undefined ? 0 : _options$delay,
_options$loopDelay = options.loopDelay,
loopDelay = _options$loopDelay === undefined ? 0 : _options$loopDelay,
_options$rewind = options.rewind,
rewind = _options$rewind === undefined ? false : _options$rewind,
change = options.change,
done = options.done;
var _options$loop = options.loop,
loop = _options$loop === undefined ? 1 : _options$loop;
if (loop === false) loop = 1;
var data = {
from: from,
to: to,
duration: duration,
delay: delay,
loopDelay: loopDelay,
loop: loop,
easing: easing,
rewind: rewind,
change: change,
done: done
};
data = Object.assign({}, data, calcStartEnd(delay, duration));
data.iteration = 1;
var raf = requestAnimationFrame(function () {
return tick(data, raf, resolve);
});
});
});