From f5dd6679ee59c82712626d71d762d7f74d5f8442 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Thu, 23 Mar 2023 16:37:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/fukasawa/components/Catalog.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/themes/fukasawa/components/Catalog.js b/themes/fukasawa/components/Catalog.js index b9ed5809..dc924a7c 100644 --- a/themes/fukasawa/components/Catalog.js +++ b/themes/fukasawa/components/Catalog.js @@ -1,4 +1,4 @@ -import React, { useRef } from 'react' +import React, { useCallback, useRef } from 'react' import throttle from 'lodash.throttle' import { uuidToId } from 'notion-utils' import { useGlobal } from '@/lib/global' @@ -28,7 +28,7 @@ const Catalog = ({ toc }) => { // 同步选中目录事件 const [activeSection, setActiveSection] = React.useState(null) const throttleMs = 200 - const actionSectionScrollSpy = React.useCallback(throttle(() => { + const actionSectionScrollSpy = useCallback(throttle(() => { const sections = document.getElementsByClassName('notion-h') let prevBBox = null let currentSectionId = activeSection @@ -52,6 +52,7 @@ const Catalog = ({ toc }) => { } setActiveSection(currentSectionId) const index = tocIds.indexOf(currentSectionId) || 0 + console.log('滚动目录', tRef.current) tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' }) }, throttleMs)) @@ -60,10 +61,10 @@ const Catalog = ({ toc }) => { return <> } - return
+ return
{locale.COMMON.TABLE_OF_CONTENTS}
-
-