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}
))}
)
};