/* eslint-disable no-unreachable */ import throttle from 'lodash.throttle'; import { useCallback, useEffect } from 'react' import { MenuList } from './MenuList'; import { DarkModeButton } from './DarkModeButton'; import { Logo } from './Logo'; import { useRouter } from 'next/router'; import { siteConfig } from '@/lib/config'; import CONFIG from '../config'; /** * 顶部导航栏 */ export const NavBar = (props) => { const router = useRouter() useEffect(() => { // ======= Sticky window.addEventListener('scroll', navBarScollListener) return () => { window.removeEventListener('scroll', navBarScollListener) } }, []) // 滚动监听 const throttleMs = 200 const navBarScollListener = useCallback( throttle(() => { // eslint-disable-next-line camelcase const ud_header = document.querySelector('.ud-header'); const scrollY = window.scrollY; // 控制台输出当前滚动位置和 sticky 值 if (scrollY > 0) { ud_header?.classList?.add('sticky'); } else { ud_header?.classList?.remove('sticky'); } }, throttleMs) ) return <> {/* */}
{/* Logo */}
{/* 中间菜单 */} {/* 右侧功能 */}
{/* */} }