diff --git a/themes/heo/components/MenuItemDrop.js b/themes/heo/components/MenuItemDrop.js index fe8fdf53d82..3e6f2c8190c 100644 --- a/themes/heo/components/MenuItemDrop.js +++ b/themes/heo/components/MenuItemDrop.js @@ -17,7 +17,6 @@ export const MenuItemDrop = ({ link }) => { href={link?.to} className="font-sans hover:bg-black hover:bg-opacity-10 rounded-2xl flex justify-center items-center px-3 py-1 no-underline tracking-widest"> {link?.icon && } {link?.name} - {hasSubMenu && } } {/* 含子菜单的按钮 */} diff --git a/themes/heo/components/NavBar.js b/themes/heo/components/NavBar.js index a24130e4ec3..277e95b842c 100644 --- a/themes/heo/components/NavBar.js +++ b/themes/heo/components/NavBar.js @@ -5,7 +5,9 @@ import RandomPostButton from './RandomPostButton' import SearchButton from './SearchButton' import SlideOver from './SlideOver' import ReadingProgress from './ReadingProgress' -import NavBarSwipe from './NavBarSwipe' +import { MenuListTop } from './MenuListTop' +import { isBrowser } from '@/lib/utils' +import BLOG from '@/blog.config' /** * 顶部导航 * @param {*} param0 @@ -15,6 +17,9 @@ const NavBar = props => { const [fixedNav, setFixedNav] = useState(false) const [textWhite, setTextWhite] = useState(false) const [navBgWhite, setBgWhite] = useState(false) + + const [activeIndex, setActiveIndex] = useState(0) + const slideOverRef = useRef() const toggleMenuOpen = () => { @@ -33,8 +38,8 @@ const NavBar = props => { const throttleMs = 200 /** - * 根据滚动条,切换导航栏样式 - */ + * 根据滚动条,切换导航栏样式 + */ const scrollTrigger = useCallback(throttle(() => { const scrollS = window.scrollY @@ -57,7 +62,74 @@ const NavBar = props => { } }, throttleMs)) + // 监听导航栏显示文字 + useEffect(() => { + let prevScrollY = 0 + let ticking = false + + const handleScroll = () => { + if (!ticking) { + window.requestAnimationFrame(() => { + const currentScrollY = window.scrollY + + if (currentScrollY > prevScrollY) { + setActiveIndex(1) // 向下滚动时设置activeIndex为1 + } else { + setActiveIndex(0) // 向上滚动时设置activeIndex为0 + } + + prevScrollY = currentScrollY + ticking = false + }) + + ticking = true + } + } + + if (isBrowser()) { + window.addEventListener('scroll', handleScroll) + } + + return () => { + if (isBrowser()) { + window.removeEventListener('scroll', handleScroll) + } + } + }, []) + return (<> + + {/* 顶部导航菜单栏 */} ) diff --git a/themes/heo/components/NavBarSwipe.js b/themes/heo/components/NavBarSwipe.js deleted file mode 100644 index 29fdc5503a7..00000000000 --- a/themes/heo/components/NavBarSwipe.js +++ /dev/null @@ -1,106 +0,0 @@ -import BLOG from '@/blog.config' -import { isBrowser } from '@/lib/utils' -import { useEffect, useState } from 'react' -import { MenuListTop } from './MenuListTop' - -/** - * 一个swipe组件 - * 垂直方向,g给导航栏用 - * @param {*} param0 - * @returns - */ -export default function NavSwipe(props) { - const [activeIndex, setActiveIndex] = useState(0) - - const item1 = ( -
-
- -
-
- ) - - const item2 =

{BLOG.AUTHOR || BLOG.TITLE} | {BLOG.BIO}

- const items = [item1, item2] - - useEffect(() => { - let prevScrollY = 0 - let ticking = false - - const handleScroll = () => { - if (!ticking) { - window.requestAnimationFrame(() => { - const currentScrollY = window.scrollY - - if (currentScrollY > prevScrollY) { - setActiveIndex(1) // 向下滚动时设置activeIndex为1 - } else { - setActiveIndex(0) // 向上滚动时设置activeIndex为0 - } - - prevScrollY = currentScrollY - ticking = false - }) - - ticking = true - } - } - - if (isBrowser()) { - window.addEventListener('scroll', handleScroll) - } - - return () => { - if (isBrowser()) { - window.removeEventListener('scroll', handleScroll) - } - } - }, []) - - return ( -
- {items.map((item, index) => ( -
- {item} -
- ))} - - -
- ) -};