Merge pull request #2965 from tangly1024/fix/theme-magzine-nav-auto-collapse

Magzine主题,移动端自动收起菜单
This commit is contained in:
tangly1024
2024-11-14 10:31:02 +08:00
committed by GitHub
3 changed files with 13 additions and 3 deletions

View File

@@ -62,11 +62,12 @@ export default function Header(props) {
// 向下滚动时,调整导航条高度
useEffect(() => {
scrollTrigger()
changeShow(false)
window.addEventListener('scroll', scrollTrigger)
return () => {
window.removeEventListener('scroll', scrollTrigger)
}
}, [])
}, [router])
const throttleMs = 150

View File

@@ -1,7 +1,11 @@
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { MenuItemCollapse } from './MenuItemCollapse'
/**
* 移动端菜单
* @param {*} props
* @returns
*/
export const MenuBarMobile = props => {
const { customMenu, customNav } = props
const { locale } = useGlobal()

View File

@@ -1,7 +1,7 @@
import Collapse from '@/components/Collapse'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { useEffect, useState } from 'react'
/**
* 折叠菜单
@@ -31,6 +31,11 @@ export const MenuItemCollapse = props => {
changeIsOpen(!isOpen)
}
// 路由切换时菜单收起
useEffect(() => {
changeIsOpen(false)
}, [router])
return (
<>
<div