diff --git a/components/DebugPanel.js b/components/DebugPanel.js index 1c5ebea6..01e3c579 100644 --- a/components/DebugPanel.js +++ b/components/DebugPanel.js @@ -69,7 +69,7 @@ export function DebugPanel() { {/* 调试侧拉抽屉 */}
diff --git a/components/Tabs.js b/components/Tabs.js index 4e834b93..b354e533 100644 --- a/components/Tabs.js +++ b/components/Tabs.js @@ -52,7 +52,6 @@ const Tabs = ({ className, children }) => { return
{currentTab === index && item} diff --git a/pages/_app.js b/pages/_app.js index 9a881d47..ce4cfd54 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -1,5 +1,5 @@ import BLOG from 'blog.config' -import React from 'react' +import React, { useEffect } from 'react' import dynamic from 'next/dynamic' import 'animate.css' @@ -20,7 +20,6 @@ import { Sakura } from '@/components/Sakura' import { StarrySky } from '@/components/StarrySky' import MusicPlayer from '@/components/MusicPlayer' import ExternalScript from '@/components/ExternalScript' -import { isBrowser } from '@/lib/utils' import smoothscroll from 'smoothscroll-polyfill' import AOS from 'aos' @@ -56,10 +55,10 @@ const MyApp = ({ Component, pageProps }) => { - if (isBrowser()) { + useEffect(() => { AOS.init() smoothscroll.polyfill() - } + }) return ( diff --git a/themes/fukasawa/components/Card.js b/themes/fukasawa/components/Card.js index 82446d9d..a330210d 100644 --- a/themes/fukasawa/components/Card.js +++ b/themes/fukasawa/components/Card.js @@ -2,7 +2,6 @@ const Card = ({ children, headerSlot, className }) => { return
diff --git a/themes/hexo/LayoutBase.js b/themes/hexo/LayoutBase.js index 15c3a2e0..a9ec3442 100644 --- a/themes/hexo/LayoutBase.js +++ b/themes/hexo/LayoutBase.js @@ -27,7 +27,7 @@ const FacebookPage = dynamic( */ const LayoutBase = props => { const { children, headerSlot, floatSlot, meta, siteInfo } = props - const [show, switchShow] = useState(false) + const [showFloatButton, switchShow] = useState(false) // const [percent, changePercent] = useState(0) // 页面阅读百分比 const rightAreaSlot = ( <> @@ -47,7 +47,7 @@ const LayoutBase = props => { if (per > 100) per = 100 const shouldShow = scrollY > 100 && per > 0 - if (shouldShow !== show) { + if (shouldShow !== showFloatButton) { switchShow(shouldShow) } // changePercent(per) @@ -56,7 +56,7 @@ const LayoutBase = props => { useEffect(() => { document.addEventListener('scroll', scrollListener) return () => document.removeEventListener('scroll', scrollListener) - }, [show]) + }, []) return (
@@ -79,7 +79,7 @@ const LayoutBase = props => { {/* 右下角悬浮 */} -
+
{floatSlot} diff --git a/themes/hexo/components/Announcement.js b/themes/hexo/components/Announcement.js index eea45676..18cb3f8a 100644 --- a/themes/hexo/components/Announcement.js +++ b/themes/hexo/components/Announcement.js @@ -9,7 +9,6 @@ const Announcement = ({ post, className }) => { return
diff --git a/themes/hexo/components/BlogPostCard.js b/themes/hexo/components/BlogPostCard.js index 108ac6fa..895a77ec 100644 --- a/themes/hexo/components/BlogPostCard.js +++ b/themes/hexo/components/BlogPostCard.js @@ -15,11 +15,11 @@ const BlogPostCard = ({ post, showSummary, siteInfo }) => {
diff --git a/themes/hexo/components/Card.js b/themes/hexo/components/Card.js index 26c3093a..285554ca 100644 --- a/themes/hexo/components/Card.js +++ b/themes/hexo/components/Card.js @@ -1,7 +1,7 @@ const Card = ({ children, headerSlot, className }) => { return
<>{headerSlot} -
+
{children}
diff --git a/themes/hexo/components/TopNav.js b/themes/hexo/components/TopNav.js index 4e020cba..374f59ce 100644 --- a/themes/hexo/components/TopNav.js +++ b/themes/hexo/components/TopNav.js @@ -18,18 +18,32 @@ let windowTop = 0 * @returns */ const TopNav = props => { + const searchDrawer = useRef() const { tags, currentTag, categories, currentCategory } = props const { locale } = useGlobal() - const searchDrawer = useRef() const { isDarkMode } = useGlobal() const router = useRouter() + const [isOpen, changeShow] = useState(false) + + const toggleMenuOpen = () => { + changeShow(!isOpen) + } + + // 监听滚动 + useEffect(() => { + scrollTrigger() + window.addEventListener('scroll', scrollTrigger) + return () => { + window.removeEventListener('scroll', scrollTrigger) + } + }, []) + const scrollTrigger = () => { requestAnimationFrame(() => { const scrollS = window.scrollY const nav = document.querySelector('#sticky-nav') const header = document.querySelector('#header') - const showNav = scrollS <= windowTop || scrollS < 5 || (header && scrollS <= header.clientHeight)// 非首页无大图时影藏顶部 滚动条置顶时隐藏 // 是否将导航栏透明 const navTransparent = (scrollS < document.documentElement.clientHeight - 12 && router.route === '/') || scrollS < 300 // 透明导航条的条件 @@ -47,6 +61,7 @@ const TopNav = props => { nav && nav.classList.replace('transparent', 'dark:bg-hexo-black-gray') } + const showNav = scrollS <= windowTop || scrollS < 5 || (header && scrollS <= header.clientHeight)// 非首页无大图时影藏顶部 滚动条置顶时隐藏 if (!showNav) { nav && nav.classList.replace('top-0', '-top-20') windowTop = scrollS @@ -70,21 +85,6 @@ const TopNav = props => { } } - const [isOpen, changeShow] = useState(false) - - const toggleMenuOpen = () => { - changeShow(!isOpen) - } - - // 监听滚动 - useEffect(() => { - scrollTrigger() - window.addEventListener('scroll', scrollTrigger) - return () => { - window.removeEventListener('scroll', scrollTrigger) - } - }, []) - const searchDrawerSlot = <> {categories && (
@@ -127,7 +127,7 @@ const TopNav = props => { {/* 导航栏 */} -