在写 js 动画的时候常用 requestAnimationFrame
这个函数,但会有必定的 兼容问题。今天在 ecomfe/zrender 看到一种降级写法,特此记录:git
// requestAnimationFrame.js
export default (
typeof window !== 'undefined'
&& (
(window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
|| (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
)
) || function (func) {
setTimeout(func, 16);
};
复制代码