From 1363cb5947b24ae79d7e4ae49c49d74c442e7cc4 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Wed, 16 Apr 2025 10:00:48 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/hexo/components/RightFloatArea.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/themes/hexo/components/RightFloatArea.js b/themes/hexo/components/RightFloatArea.js index 1facb110..6759fe05 100644 --- a/themes/hexo/components/RightFloatArea.js +++ b/themes/hexo/components/RightFloatArea.js @@ -12,19 +12,22 @@ export default function RightFloatArea({ floatSlot }) { const [showFloatButton, switchShow] = useState(false) const scrollListener = useCallback(() => { - const targetRef = document.getElementById('wrapper') || document.documentElement + const targetRef = + document.getElementById('wrapper') || document.documentElement const clientHeight = targetRef?.clientHeight || 0 - const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0 - const viewportHeight = window.innerHeight || document.documentElement.clientHeight || 0 - + const scrollY = + window.pageYOffset || document.documentElement.scrollTop || 0 + const viewportHeight = + window.innerHeight || document.documentElement.clientHeight || 0 + const fullHeight = Math.max(1, clientHeight - viewportHeight) - + let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0)) - + // 完整的边界处理 if (isNaN(per) || per < 0) per = 0 if (per > 100) per = 100 - + const shouldShow = scrollY > 100 && per > 0 // 右下角显示悬浮按钮 @@ -39,12 +42,12 @@ export default function RightFloatArea({ floatSlot }) { scrollListener() }) } - + window.addEventListener('scroll', throttledScroll) - + // 初始调用一次检查初始状态 scrollListener() - + return () => window.removeEventListener('scroll', throttledScroll) }, [scrollListener])