You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
960 B
43 lines
960 B
2 years ago
|
(function (global, factory) {
|
||
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||
|
typeof define === 'function' && define.amd ? define(factory) :
|
||
|
(global = global || self, global.rafSchd = factory());
|
||
|
}(this, function () { 'use strict';
|
||
|
|
||
|
var rafSchd = function rafSchd(fn) {
|
||
|
var lastArgs = [];
|
||
|
var frameId = null;
|
||
|
|
||
|
var wrapperFn = function wrapperFn() {
|
||
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||
|
args[_key] = arguments[_key];
|
||
|
}
|
||
|
|
||
|
lastArgs = args;
|
||
|
|
||
|
if (frameId) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
frameId = requestAnimationFrame(function () {
|
||
|
frameId = null;
|
||
|
fn.apply(void 0, lastArgs);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
wrapperFn.cancel = function () {
|
||
|
if (!frameId) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
cancelAnimationFrame(frameId);
|
||
|
frameId = null;
|
||
|
};
|
||
|
|
||
|
return wrapperFn;
|
||
|
};
|
||
|
|
||
|
return rafSchd;
|
||
|
|
||
|
}));
|