From 5b69aaa3a52d8245b7ae845cdb20e3153b673e85 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 12 Jan 2022 12:37:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feature:=20=E6=82=AC=E6=B5=AE=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E8=B0=83=E6=95=B4=EF=BC=9B=20=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/FloatDarkModeButton.js | 2 +- components/JumpToBottomButton.js | 4 ++-- components/JumpToTopButton.js | 2 +- components/Progress.js | 22 +++++++++++++++------- components/SideAreaLeft.js | 2 +- components/Toc.js | 4 ++-- components/TocDrawer.js | 4 ++-- components/TocDrawerButton.js | 2 +- layouts/BaseLayout.js | 15 ++++++++------- 9 files changed, 33 insertions(+), 24 deletions(-) diff --git a/components/FloatDarkModeButton.js b/components/FloatDarkModeButton.js index bf01f26b..6a286fcd 100644 --- a/components/FloatDarkModeButton.js +++ b/components/FloatDarkModeButton.js @@ -24,7 +24,7 @@ export default function FloatDarkModeButton () { return (
{ return () => document.removeEventListener('scroll', scrollListener) }, [show]) - return (
+ return (
- {showPercent && (
{percent}%
)} + {showPercent && (
{percent}%
)}
) } diff --git a/components/JumpToTopButton.js b/components/JumpToTopButton.js index f72ee0fa..9fb58f9e 100644 --- a/components/JumpToTopButton.js +++ b/components/JumpToTopButton.js @@ -17,7 +17,7 @@ const JumpToTopButton = ({ showPercent = true, percent }) => { return <> } const { locale } = useGlobal() - return (
window.scrollTo({ top: 0, behavior: 'smooth' })} > + return (
window.scrollTo({ top: 0, behavior: 'smooth' })} >
diff --git a/components/Progress.js b/components/Progress.js index a46ae098..4c4adb9f 100644 --- a/components/Progress.js +++ b/components/Progress.js @@ -9,11 +9,12 @@ const Progress = ({ targetRef, showPercent = true }) => { const currentRef = targetRef?.current || targetRef const [percent, changePercent] = useState(0) const scrollListener = () => { - if (currentRef) { - const clientHeight = currentRef ? (currentRef.clientHeight) : 0 + const target = currentRef || document.getElementById('container') + if (target) { + const clientHeight = target.clientHeight const scrollY = window.pageYOffset const fullHeight = clientHeight - window.outerHeight - let per = parseFloat(((scrollY / fullHeight * 100)).toFixed(0)) + let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0)) if (per > 100) per = 100 if (per < 0) per = 0 changePercent(per) @@ -25,11 +26,18 @@ const Progress = ({ targetRef, showPercent = true }) => { return () => document.removeEventListener('scroll', scrollListener) }, [percent]) - return (
-
- {showPercent &&
{percent}%
} + return ( +
+
+ {showPercent && ( +
{percent}%
+ )}
-
) +
+ ) } export default Progress diff --git a/components/SideAreaLeft.js b/components/SideAreaLeft.js index 77d6c66f..51c1bb81 100644 --- a/components/SideAreaLeft.js +++ b/components/SideAreaLeft.js @@ -44,7 +44,7 @@ const SideAreaLeft = ({ title, tags, currentTag, post, postCount, categories, cu {showToc && (
- +
)} diff --git a/components/Toc.js b/components/Toc.js index 4bd1aa21..676dbbd2 100644 --- a/components/Toc.js +++ b/components/Toc.js @@ -10,7 +10,7 @@ import Progress from './Progress' * @returns {JSX.Element} * @constructor */ -const Toc = ({ toc, targetRef }) => { +const Toc = ({ toc }) => { // 无目录就直接返回空 if (!toc || toc.length < 1) { return <> @@ -54,7 +54,7 @@ const Toc = ({ toc, targetRef }) => { return <>
- +
- +
} diff --git a/components/TocDrawerButton.js b/components/TocDrawerButton.js index e828290e..06dc454b 100644 --- a/components/TocDrawerButton.js +++ b/components/TocDrawerButton.js @@ -16,7 +16,7 @@ const TocDrawerButton = (props) => { return <> } const { locale } = useGlobal() - return (
+ return (
) } diff --git a/layouts/BaseLayout.js b/layouts/BaseLayout.js index 7418b0c4..a516fced 100644 --- a/layouts/BaseLayout.js +++ b/layouts/BaseLayout.js @@ -96,15 +96,16 @@ const BaseLayout = ({ -
-
- - - - {floatSlot} + {/* 右下角悬浮 */} +
+
+ + + + {floatSlot} +
-