diff --git a/themes/heo/components/Logo.js b/themes/heo/components/Logo.js index a57cea2e..d3a9ba2c 100644 --- a/themes/heo/components/Logo.js +++ b/themes/heo/components/Logo.js @@ -7,14 +7,14 @@ const Logo = props => { const { siteInfo } = props return ( -
+
{/* eslint-disable-next-line @next/next/no-img-element */} {BLOG.AUTHOR} -
+
{siteInfo?.title || BLOG.TITLE}
-
+
diff --git a/themes/heo/components/NavBar.js b/themes/heo/components/NavBar.js index 297df23b..a24130e4 100644 --- a/themes/heo/components/NavBar.js +++ b/themes/heo/components/NavBar.js @@ -1,12 +1,11 @@ import { useCallback, useEffect, useRef, useState } from 'react' import Logo from './Logo' - -import { MenuListTop } from './MenuListTop' import throttle from 'lodash.throttle' import RandomPostButton from './RandomPostButton' import SearchButton from './SearchButton' import SlideOver from './SlideOver' import ReadingProgress from './ReadingProgress' +import NavBarSwipe from './NavBarSwipe' /** * 顶部导航 * @param {*} param0 @@ -68,9 +67,7 @@ const NavBar = props => {
{/* 中间菜单 */} -
-
-
+ {/* 右侧固定 */}
diff --git a/themes/heo/components/NavBarSwipe.js b/themes/heo/components/NavBarSwipe.js new file mode 100644 index 00000000..271b3be3 --- /dev/null +++ b/themes/heo/components/NavBarSwipe.js @@ -0,0 +1,106 @@ +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} +
+ ))} + + +
+ ) +};