Fix scroll transition of BackTop, close #5564

This commit is contained in:
afc163 2017-03-30 14:20:06 +08:00
parent 51f1403e14
commit 5ba4014386

View File

@ -9,10 +9,6 @@ import getRequestAnimationFrame from '../_util/getRequestAnimationFrame';
const reqAnimFrame = getRequestAnimationFrame();
const currentScrollTop = () => {
return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
};
const easeInOutCubic = (t, b, c, d) => {
const cc = c - b;
t /= d / 2;
@ -53,8 +49,16 @@ export default class BackTop extends React.Component<BackTopProps, any> {
};
}
getCurrentScrollTop = () => {
const targetNode = (this.props.target || getDefaultTarget)();
if (targetNode === window) {
return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
}
return (targetNode as HTMLElement).scrollTop;
}
scrollToTop = (e) => {
const scrollTop = currentScrollTop();
const scrollTop = this.getCurrentScrollTop();
const startTime = Date.now();
const frameFunc = () => {
const timestamp = Date.now();