diff --git a/themes/fukasawa/components/Catalog.js b/themes/fukasawa/components/Catalog.js
index 477a325e..c4425454 100644
--- a/themes/fukasawa/components/Catalog.js
+++ b/themes/fukasawa/components/Catalog.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { useRef } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
@@ -22,6 +22,10 @@ const Catalog = ({ toc }) => {
}
}, [])
+ // 目录自动滚动
+ const tRef = useRef(null)
+ const tocIds = []
+
// 同步选中目录事件
const [activeSection, setActiveSection] = React.useState(null)
const throttleMs = 100
@@ -48,33 +52,34 @@ const Catalog = ({ toc }) => {
break
}
setActiveSection(currentSectionId)
+ const index = tocIds.indexOf(currentSectionId) || 0
+ tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}, throttleMs))
return
目录
-
+
+
+
}
diff --git a/themes/hexo/components/Catalog.js b/themes/hexo/components/Catalog.js
index 8045800d..8b1db5f0 100644
--- a/themes/hexo/components/Catalog.js
+++ b/themes/hexo/components/Catalog.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { useRef } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
import Progress from './Progress'
@@ -23,6 +23,10 @@ const Catalog = ({ toc }) => {
}
}, [])
+ // 目录自动滚动
+ const tRef = useRef(null)
+ const tocIds = []
+
// 同步选中目录事件
const [activeSection, setActiveSection] = React.useState(null)
const throttleMs = 100
@@ -49,6 +53,8 @@ const Catalog = ({ toc }) => {
break
}
setActiveSection(currentSectionId)
+ const index = tocIds.indexOf(currentSectionId) || 0
+ tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}, throttleMs))
return
}
diff --git a/themes/hexo/components/TocDrawer.js b/themes/hexo/components/TocDrawer.js
index 54cad1fb..7df6d309 100644
--- a/themes/hexo/components/TocDrawer.js
+++ b/themes/hexo/components/TocDrawer.js
@@ -24,8 +24,8 @@ const TocDrawer = ({ post, cRef }) => {
{/* 侧边菜单 */}
+ ' shadow-card animate__animated animate__faster' +
+ ' w-60 duration-200 fixed right-12 bottom-12 rounded py-2 bg-white dark:bg-gray-600'}>
{post && <>
diff --git a/themes/medium/components/Catalog.js b/themes/medium/components/Catalog.js
index 3c3bbebc..7da94669 100644
--- a/themes/medium/components/Catalog.js
+++ b/themes/medium/components/Catalog.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { useRef } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
import Progress from './Progress'
@@ -23,6 +23,10 @@ const Catalog = ({ toc }) => {
}
}, [])
+ // 目录自动滚动
+ const tRef = useRef(null)
+ const tocIds = []
+
// 同步选中目录事件
const [activeSection, setActiveSection] = React.useState(null)
const throttleMs = 100
@@ -49,35 +53,36 @@ const Catalog = ({ toc }) => {
break
}
setActiveSection(currentSectionId)
+ const index = tocIds.indexOf(currentSectionId) || 0
+ tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}, throttleMs))
return
-
+
+
+
}
diff --git a/themes/next/components/Toc.js b/themes/next/components/Toc.js
index 22ca4bc0..44202ccd 100644
--- a/themes/next/components/Toc.js
+++ b/themes/next/components/Toc.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { useRef } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
import Progress from './Progress'
@@ -24,6 +24,10 @@ const Toc = ({ toc }) => {
}
}, [])
+ // 目录自动滚动
+ const tRef = useRef(null)
+ const tocIds = []
+
// 同步选中目录事件
const [activeSection, setActiveSection] = React.useState(null)
const throttleMs = 100
@@ -50,35 +54,34 @@ const Toc = ({ toc }) => {
break
}
setActiveSection(currentSectionId)
+ const index = tocIds.indexOf(currentSectionId) || 0
+ tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}, throttleMs))
return
-
+
+
+
}
diff --git a/themes/next/components/TocDrawer.js b/themes/next/components/TocDrawer.js
index 72cbefe3..83861934 100644
--- a/themes/next/components/TocDrawer.js
+++ b/themes/next/components/TocDrawer.js
@@ -26,8 +26,8 @@ const TocDrawer = ({ post, cRef }) => {
{/* 侧边菜单 */}
+ ' shadow-card animate__animated animate__faster ' +
+ ' w-60 duration-200 fixed right-4 top-16 rounded py-2 bg-white dark:bg-gray-600'}>
{post && <>
{locale.COMMON.TABLE_OF_CONTENTS}