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 ( -