Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions src/common/header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HeaderNav from './HeaderNav';
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import Countdown from 'react-countdown';
import './header.css';
Expand All @@ -10,6 +10,50 @@ const Header = () => {
const pathName = location.pathname;

const [reset, setReset] = useState({ search: false, filter: false });
const [showNav, setShowNav] = useState(true);
const lastScrollY = useRef(0);

useEffect(() => {
const handleScroll = () => {
const current = window.scrollY;

const hero = document.getElementById('hero');

if (hero) {
const heroBottom = hero.getBoundingClientRect().bottom;
const headerHeight = 64; // your navbar height

const banner = document.querySelector('.activity-timer-banner');
const bannerHeight = banner?.offsetHeight || 0;

if (heroBottom > headerHeight + bannerHeight) {
setShowNav(true);
lastScrollY.current = current;

return;
}
}

// after hero → direction based (with threshold)
const SCROLL_THRESHOLD = 20;
const diff = Math.abs(current - lastScrollY.current);

// ignore tiny scrolls
if (diff < SCROLL_THRESHOLD) return;

if (current > lastScrollY.current) {
setShowNav(false); // down
} else {
setShowNav(true); // up
}

lastScrollY.current = current;
};

window.addEventListener('scroll', handleScroll);

return () => window.removeEventListener('scroll', handleScroll);
}, []);

useEffect(() => {
if (location.state) {
Expand Down Expand Up @@ -95,7 +139,7 @@ const Header = () => {
};

return (
<>
<div className={`nav-wrapper ${showNav ? 'nav--visible' : 'nav--hidden'}`}>
{process.env.REACT_APP_ACTIVITIES_ON === 'true' && showHideBits.showActivityTimer && (
<Countdown date={new Date(1675209600000)} renderer={activityTimerRenderer} />
)}
Expand All @@ -122,7 +166,7 @@ const Header = () => {

<HeaderNav showBrowse={showHideBits.showBrowse} />
</header>
</>
</div>
);
};

Expand Down
26 changes: 23 additions & 3 deletions src/common/header/header.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.app-header {
position: relative;
/* position: fixed;
top: 0;
right: 0;
left: 0;
left: 0; */
transition: transform 0.3s ease;
z-index: 10;
display: flex;
justify-content: space-between;
Expand All @@ -14,14 +15,33 @@
padding: 0 1rem 0 0.6rem;
}

.nav-wrapper {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10;
transition: transform 0.3s ease;
}

.nav--hidden {
transform: translateY(-100%);
}

.nav--visible {
transform: translateY(0);
}



@media screen and (max-width: 768px) {
.app-header {
padding: 0 1rem 0 0.2rem;
}
}

.app-header-home {
position: sticky;
/* position: sticky; */
}

.app-header-home.app-header-home--promo {
Expand Down
2 changes: 1 addition & 1 deletion src/common/home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DefaultBanner from 'common/defaultBanner/DefaultBanner';
const Home = () => {
return (
<main>
<section className="app-home-body">
<section className="app-home-body" id="hero">
<DefaultBanner />
</section>
<section className="home-features">
Expand Down
Loading