From 85bf3427185d3d1a839d66cebfb7c91df1c1f301 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 14 Oct 2021 19:37:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/JumpToTop.js | 3 ++- components/Progress.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/JumpToTop.js b/components/JumpToTop.js index f269be31..cf6d65ae 100644 --- a/components/JumpToTop.js +++ b/components/JumpToTop.js @@ -16,8 +16,9 @@ const JumpToTop = ({ targetRef, showPercent = true }) => { const [percent, changePercent] = useState(0) const scrollListener = useCallback(throttle(() => { // 处理是否显示回到顶部按钮 + const clientHeight = targetRef ? (targetRef.current.clientHeight) : 0 const scrollY = window.pageYOffset - const fullHeight = targetRef.current.clientHeight - window.outerHeight + const fullHeight = clientHeight - window.outerHeight const shouldShow = scrollY > 100 if (shouldShow !== show) { switchShow(shouldShow) diff --git a/components/Progress.js b/components/Progress.js index a3d27297..6a9c3055 100644 --- a/components/Progress.js +++ b/components/Progress.js @@ -10,8 +10,9 @@ const Progress = ({ targetRef }) => { const [percent, changePercent] = useState(0) const scrollListener = useCallback(throttle(() => { if (targetRef.current) { + const clientHeight = targetRef ? (targetRef.current.clientHeight) : 0 const scrollY = window.pageYOffset - const fullHeight = targetRef.current.clientHeight - window.outerHeight + const fullHeight = clientHeight - window.outerHeight let per = parseFloat(((scrollY / fullHeight * 100)).toFixed(0)) if (per > 100) per = 100 changePercent(per)