uv-ui
Version:
基于vue3的移动端组件库
30 lines (29 loc) • 849 B
JavaScript
const w = () => {
let r = 0, e = null, n = null;
const m = "webkit moz ms o".split(" ");
if (typeof window > "u")
e = function() {
}, n = function() {
};
else {
e = window.requestAnimationFrame, n = window.cancelAnimationFrame;
let t;
for (let i = 0; i < m.length && !(e && n); i++)
t = m[i], e = e || window[t + "RequestAnimationFrame"], n = n || window[t + "CancelAnimationFrame"] || window[t + "CancelRequestAnimationFrame"];
(!e || !n) && (e = function(i) {
const o = new Date().getTime(), a = Math.max(0, 16 - (o - r)), l = window.setTimeout(() => {
i(o + a);
}, a);
return r = o + a, l;
}, n = function(i) {
window.clearTimeout(i);
});
}
return {
requestAnimationFrame: e,
cancelAnimationFrame: n
};
};
export {
w as useRequestAnimationFrame
};