在寫 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);
};
複製代碼