Browse Source

Fix scroll transition of BackTop, close #5564

pull/5459/merge
afc163 8 years ago
parent
commit
5ba4014386
  1. 14
      components/back-top/index.tsx

14
components/back-top/index.tsx

@ -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();

Loading…
Cancel
Save