From 8cf5aea4b564cb1c58c21a0363e19d26848a47da Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sun, 1 Jan 2023 19:37:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/hexo/components/Catalog.js | 10 ++++++---- themes/matery/components/Catalog.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/themes/hexo/components/Catalog.js b/themes/hexo/components/Catalog.js index c51ee499..9c80cd1a 100644 --- a/themes/hexo/components/Catalog.js +++ b/themes/hexo/components/Catalog.js @@ -10,10 +10,6 @@ import Progress from './Progress' * @constructor */ const Catalog = ({ toc }) => { - // 无目录就直接返回空 - if (!toc || toc.length < 1) { - return <> - } // 监听滚动事件 React.useEffect(() => { window.addEventListener('scroll', actionSectionScrollSpy) @@ -29,6 +25,7 @@ const Catalog = ({ toc }) => { // 同步选中目录事件 const [activeSection, setActiveSection] = React.useState(null) + const throttleMs = 100 const actionSectionScrollSpy = React.useCallback(throttle(() => { const sections = document.getElementsByClassName('notion-h') @@ -57,6 +54,11 @@ const Catalog = ({ toc }) => { tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' }) }, throttleMs)) + // 无目录就直接返回空 + if (!toc || toc.length < 1) { + return <> + } + return
目录
diff --git a/themes/matery/components/Catalog.js b/themes/matery/components/Catalog.js index c5a3e3db..c3df56f0 100644 --- a/themes/matery/components/Catalog.js +++ b/themes/matery/components/Catalog.js @@ -63,7 +63,7 @@ const Catalog = ({ toc }) => {
-
+