Hexo导航栏微调

This commit is contained in:
tlyong1992
2022-06-16 14:52:34 +08:00
parent 8431960d99
commit f2ce99f754
4 changed files with 33 additions and 67 deletions

View File

@@ -1,4 +1,3 @@
import { useGlobal } from '@/lib/global'
import { useEffect, useState } from 'react'
import Typed from 'typed.js'
import CONFIG_HEXO from '../config_hexo'
@@ -13,12 +12,10 @@ let autoScroll = false
*/
const Header = props => {
const [typed, changeType] = useState()
const { isDarkMode } = useGlobal()
const { siteInfo } = props
useEffect(() => {
scrollTrigger()
updateHeaderHeight()
updateTopNav()
if (!typed && window && document.getElementById('typed')) {
changeType(
new Typed('#typed', {
@@ -48,17 +45,6 @@ const Header = props => {
const scrollTrigger = () => {
const scrollS = window.scrollY
const nav = document.querySelector('#sticky-nav')
if (scrollS < 500) {
nav && nav.classList.replace('bg-white', 'bg-none')
nav && nav.classList.replace('text-black', 'text-white')
nav && nav.classList.replace('border', 'border-transparent')
} else {
nav && nav.classList.replace('bg-none', 'bg-white')
nav && nav.classList.replace('text-white', 'text-black')
nav && nav.classList.replace('border-transparent', 'border')
}
// 自动滚动
if ((scrollS > windowTop) & (scrollS < window.innerHeight) && !autoScroll
@@ -73,19 +59,6 @@ const Header = props => {
setTimeout(autoScrollEnd, 500)
}
windowTop = scrollS
updateTopNav()
}
const updateTopNav = () => {
if (!isDarkMode) {
const stickyNavElement = document.getElementById('sticky-nav')
if (window.scrollY < window.innerHeight) {
stickyNavElement?.classList?.add('dark')
} else {
stickyNavElement?.classList?.remove('dark')
}
}
}
function updateHeaderHeight () {