react-preloader-icon
Version:
SVG loading icons component for React.
24 lines (23 loc) • 803 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function loop(options) {
var duration = options.duration, _a = options.delay, delay = _a === void 0 ? 0 : _a, update = options.update;
var startTime;
var reqId;
var step = function (timestamp) {
if (!startTime) {
startTime = timestamp + delay;
}
if (timestamp > startTime) {
var pastTime = timestamp - startTime;
var progress = (pastTime % duration) / duration;
if (update) {
update(progress);
}
}
reqId = window.requestAnimationFrame(step);
};
reqId = window.requestAnimationFrame(step);
return function () { return window.cancelAnimationFrame(reqId); };
}
exports.default = loop;