From 5ba4014386bd279ff543e3ebc282ce819e843d2a Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 30 Mar 2017 14:20:06 +0800 Subject: [PATCH] Fix scroll transition of BackTop, close #5564 --- components/back-top/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/back-top/index.tsx b/components/back-top/index.tsx index 8dad273f2f..de40725452 100755 --- a/components/back-top/index.tsx +++ b/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 { }; } + 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();