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