mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 11:08:45 +08:00
Fix back top ssr (#3418)
* improve code style * move getRequestAnimationFrame to util * Fix ssr problem in BackTop, close #3343
This commit is contained in:
parent
0981dd46c7
commit
4f77a2e5f5
12
components/_util/getRequestAnimationFrame.tsx
Normal file
12
components/_util/getRequestAnimationFrame.tsx
Normal file
@ -0,0 +1,12 @@
|
||||
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);
|
||||
}
|
@ -5,19 +5,12 @@ import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
||||
import classNames from 'classnames';
|
||||
import omit from 'omit.js';
|
||||
import getScroll from '../_util/getScroll';
|
||||
import getRequestAnimationFrame from '../_util/getRequestAnimationFrame';
|
||||
|
||||
const reqAnimFrame = (() => {
|
||||
if (window.requestAnimationFrame) {
|
||||
return window.requestAnimationFrame;
|
||||
}
|
||||
const a = ['moz', 'ms', 'webkit'];
|
||||
const raf = a.filter(key => `${key}RequestAnimationFrame` in window);
|
||||
return raf[0] ? window[`${raf[0]}RequestAnimationFrame`] :
|
||||
((callback) => window.setTimeout(callback, 1000 / 60));
|
||||
})();
|
||||
const reqAnimFrame = getRequestAnimationFrame();
|
||||
|
||||
const currentScrollTop = () => {
|
||||
return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
|
||||
return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
|
||||
};
|
||||
|
||||
const easeInOutCubic = (t, b, c, d) => {
|
||||
|
Loading…
Reference in New Issue
Block a user