From dc267f8daade1403c75f3a1475749ce45ad68d46 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Tue, 11 Aug 2020 22:29:41 -0700 Subject: [PATCH] Fix sticky header calc. --- components/helpers/StickyHeader.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/helpers/StickyHeader.js b/components/helpers/StickyHeader.js index 3db8c381..477bd393 100644 --- a/components/helpers/StickyHeader.js +++ b/components/helpers/StickyHeader.js @@ -10,15 +10,15 @@ export default function StickyHeader({ }) { const [sticky, setSticky] = useState(false); const ref = useRef(); - const offsetTop = useRef(0); + const top = useRef(0); useEffect(() => { const checkPosition = () => { if (ref.current) { - if (!offsetTop.current) { - offsetTop.current = ref.current.offsetTop; + if (!top.current) { + top.current = ref.current.offsetTop + ref.current.offsetHeight; } - const state = window.pageYOffset > offsetTop.current; + const state = window.pageYOffset > top.current; if (sticky !== state) { setSticky(state); }