diff --git a/components/Container.js b/components/Container.js index 25496fc3..7c24ff8e 100644 --- a/components/Container.js +++ b/components/Container.js @@ -1,11 +1,36 @@ import PropTypes from 'prop-types' +import React, { useEffect } from 'react' +import CommonHead from '@/components/CommonHead' +import TopNav from '@/components/TopNav' -const Container = ({ children, layout, fullWidth, ...customMeta }) => { +const Container = ({ children, layout, fullWidth, tags, meta, ...customMeta }) => { + let windowTop = 0 + // 监听滚动 + useEffect(() => { + function scrollTrigger () { + const scrollS = window.scrollY + const nav = document.querySelector('#sticky-nav') + const tagsBar = document.querySelector('#tags-bar') + console.log(windowTop, scrollS) + if (scrollS >= windowTop) { + nav && nav.classList.add('-mt-16') + tagsBar && tagsBar.classList.add('-mt-32') + windowTop = scrollS + } else { + nav && nav.classList.remove('-mt-16') + tagsBar && tagsBar.classList.remove('-mt-32') + windowTop = scrollS + } + } + + window.addEventListener('scroll', scrollTrigger) + }) return ( -
- {/* 公共头 */} + <> + + {children} -
+ ) } diff --git a/components/SideBar.js b/components/SideBar.js index 21264289..c3eb8ea2 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -6,7 +6,7 @@ const SideBar = ({ tags, currentTag, post }) => { return