mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-29 21:59:41 +08:00
4f77a2e5f5
* improve code style * move getRequestAnimationFrame to util * Fix ssr problem in BackTop, close #3343
13 lines
416 B
TypeScript
13 lines
416 B
TypeScript
export default function getRequestAnimationFrame() {
|
|
if (typeof window === 'undefined') {
|
|
return () => {};
|
|
}
|
|
if (window.requestAnimationFrame) {
|
|
return window.requestAnimationFrame;
|
|
}
|
|
const prefix = ['moz', 'ms', 'webkit'].filter(key => `${key}RequestAnimationFrame` in window)[0];
|
|
return prefix
|
|
? window[`${prefix}RequestAnimationFrame`]
|
|
: callback => setTimeout(callback, 1000 / 60);
|
|
}
|