Fix back top ssr (#3418)

* improve code style

* move getRequestAnimationFrame to util

* Fix ssr problem in BackTop, close #3343
This commit is contained in:
偏右 2016-10-13 16:26:15 +08:00 committed by Benjy Cui
parent 0981dd46c7
commit 4f77a2e5f5
2 changed files with 15 additions and 10 deletions

View 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);
}

View File

@ -5,16 +5,9 @@ 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;