This commit is contained in:
tangly1024
2023-03-25 15:19:27 +08:00
parent fadf797baa
commit 6a7fc8a2f2
5 changed files with 18 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import React, { useRef } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
import { useGlobal } from '@/lib/global'
@@ -12,7 +12,7 @@ import { useGlobal } from '@/lib/global'
const Catalog = ({ post }) => {
const { locale } = useGlobal()
// 监听滚动事件
React.useEffect(() => {
useEffect(() => {
window.addEventListener('scroll', actionSectionScrollSpy)
actionSectionScrollSpy()
return () => {
@@ -25,9 +25,9 @@ const Catalog = ({ post }) => {
const tocIds = []
// 同步选中目录事件
const [activeSection, setActiveSection] = React.useState(null)
const [activeSection, setActiveSection] = 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