From a8a8df02097156d66017a67763468a4ac2a24786 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 7 Jan 2022 11:19:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B3=E4=B8=8B=E8=A7=92=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/JumpToBottomButton.js | 3 ++- components/JumpToTopButton.js | 3 +-- components/TocDrawerButton.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/JumpToBottomButton.js b/components/JumpToBottomButton.js index e059ba68..e962d22d 100644 --- a/components/JumpToBottomButton.js +++ b/components/JumpToBottomButton.js @@ -18,11 +18,11 @@ const JumpToBottomButton = ({ showPercent = false }) => { return <> } - const targetRef = typeof window !== 'undefined' ? document.getElementById('wrapper') : undefined const { locale } = useGlobal() const [show, switchShow] = useState(false) const [percent, changePercent] = useState(0) const scrollListener = () => { + const targetRef = document.getElementById('wrapper') const clientHeight = targetRef?.clientHeight const scrollY = window.pageYOffset const fullHeight = clientHeight - window.outerHeight @@ -36,6 +36,7 @@ const JumpToBottomButton = ({ showPercent = false }) => { } function scrollToBottom () { + const targetRef = document.getElementById('wrapper') window.scrollTo({ top: targetRef.clientHeight, behavior: 'smooth' }) } diff --git a/components/JumpToTopButton.js b/components/JumpToTopButton.js index b4abc11e..ca67e0a0 100644 --- a/components/JumpToTopButton.js +++ b/components/JumpToTopButton.js @@ -20,9 +20,8 @@ const JumpToTopButton = ({ showPercent = false }) => { const { locale } = useGlobal() const [show, switchShow] = useState(false) const [percent, changePercent] = useState(0) - const targetRef = typeof window !== 'undefined' ? document.getElementById('wrapper') : undefined const scrollListener = () => { - // 处理是否显示回到顶部按钮 + const targetRef = document.getElementById('wrapper') const clientHeight = targetRef?.clientHeight const scrollY = window.pageYOffset const fullHeight = clientHeight - window.outerHeight diff --git a/components/TocDrawerButton.js b/components/TocDrawerButton.js index 3d23ef1a..9a884286 100644 --- a/components/TocDrawerButton.js +++ b/components/TocDrawerButton.js @@ -31,8 +31,8 @@ const TocDrawerButton = (props) => { }) return ( -
-
+
+