gitbook-drawer

This commit is contained in:
tangly1024
2023-06-24 21:04:13 +08:00
parent 6e61c79607
commit ffc3fb984b
2 changed files with 8 additions and 5 deletions

View File

@@ -49,8 +49,11 @@ const Catalog = ({ post }) => {
}
setActiveSection(currentSectionId)
const index = tocIds.indexOf(currentSectionId) || 0
if (isBrowser()) {
document?.getElementById('toc-wrapper')?.scrollTo({ top: 28 * index, behavior: 'smooth' })
if (isBrowser() && tocIds?.length > 0) {
console.log(28 * index, index, currentSectionId)
for (const tocWrapper of document?.getElementsByClassName('toc-wrapper')) {
tocWrapper?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}
}
}, throttleMs))
@@ -60,7 +63,7 @@ const Catalog = ({ post }) => {
}
return <>
<div id='toc-wrapper' className='max-h-96 scroll-hidden'>
<div id='toc-wrapper' className='toc-wrapper overflow-y-auto max-h-96 overscroll-none scroll-hidden'>
<nav className='h-full text-black'>
{toc.map((tocItem) => {
const id = uuidToId(tocItem.id)

View File

@@ -18,9 +18,9 @@ const TocDrawer = ({ post, cRef }) => {
{/* 侧边菜单 */}
<div
className={(tocVisible ? 'animate__slideInRight ' : ' -mr-72 animate__slideOutRight') +
' shadow-card w-60 duration-200 fixed right-1 bottom-16 rounded py-2 bg-white dark:bg-gray-900'}>
' overflow-y-hidden shadow-card w-60 duration-200 fixed right-1 bottom-16 rounded py-2 bg-white dark:bg-gray-900'}>
{post && <>
<div className='dark:text-gray-400 text-gray-600 h-56 p-3 overflow-y-scroll '>
<div className='dark:text-gray-400 text-gray-600 h-96 p-3'>
<Catalog post={post}/>
</div>
</>}