diff --git a/src/components/board-nav/board-nav.module.css b/src/components/board-nav/board-nav.module.css index d510e086..05c5cde3 100644 --- a/src/components/board-nav/board-nav.module.css +++ b/src/components/board-nav/board-nav.module.css @@ -27,25 +27,11 @@ position: fixed; width: 100%; z-index: 3; - animation-name: stickyMenuAnimation; - animation-duration: 1s; - animation-timing-function: linear; - animation-iteration-count: 1; - animation-fill-mode: both; - animation-play-state: paused; + transition: top 0.3s ease-in-out; align-items: center; justify-content: space-around; } -@keyframes stickyMenuAnimation { - 0% { - top: 0px; - } - 100% { - top: -50px; - } -} - .boardNavMobile .pageJump a { color: var(--button-text-color-mobile); text-decoration: var(--button-text-decoration-mobile); diff --git a/src/components/board-nav/board-nav.tsx b/src/components/board-nav/board-nav.tsx index 5d30ccbb..74b897b8 100644 --- a/src/components/board-nav/board-nav.tsx +++ b/src/components/board-nav/board-nav.tsx @@ -1,9 +1,11 @@ +import { useEffect, useState } from 'react'; import { useAccountComment } from '@plebbit/plebbit-react-hooks'; import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { isAllView, isCatalogView, isSubscriptionsView } from '../../lib/utils/view-utils'; import styles from './board-nav.module.css'; import useDefaultSubplebbits, { categorizeSubplebbits, useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; +import { debounce } from 'lodash'; const BoardNavDesktop = () => { const { t } = useTranslation(); @@ -67,8 +69,23 @@ const BoardNavMobile = ({ subplebbitAddress }: { subplebbitAddress: string }) => ); + // navbar animation on scroll + const [prevScrollPos, setPrevScrollPos] = useState(0); + const [visible, setVisible] = useState(true); + useEffect(() => { + const debouncedHandleScroll = debounce(() => { + const currentScrollPos = window.scrollY; + setVisible(prevScrollPos > currentScrollPos || currentScrollPos < 10); + setPrevScrollPos(currentScrollPos); + }, 50); + + window.addEventListener('scroll', debouncedHandleScroll); + + return () => window.removeEventListener('scroll', debouncedHandleScroll); + }, [prevScrollPos, visible]); + return ( -