Skip to content

Commit 708d6cb

Browse files
committed
fix: FloatingHeader margin calculation #35
1 parent 23b7760 commit 708d6cb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/velog-web/src/features/home/components/FloatingHeader/FloatingHeader.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function FloatingHeader({ header }: Props) {
2121
const [height, setHeight] = useState(0)
2222
const [marginTop, setMarginTop] = useState(0)
2323

24+
const isHome = checkIsHome(pathname)
25+
2426
useEffect(() => {
2527
if (!blockRef.current) return
2628
setHeight(blockRef.current.clientHeight)
@@ -56,11 +58,19 @@ function FloatingHeader({ header }: Props) {
5658
setVisible(false)
5759
}
5860

59-
setMarginTop(Math.min(0, -1 * height + transitionPoint.current - scrollTop))
61+
const marginTopMax = 0
62+
const marginTopMin = isHome ? -112 : -64
63+
64+
const calculatedMarginTop = Math.min(
65+
marginTopMax,
66+
-1 * height + transitionPoint.current - scrollTop,
67+
)
68+
69+
setMarginTop(Math.max(calculatedMarginTop, marginTopMin))
6070

6171
direction.current = nextDirection
6272
prevScrollTop.current = scrollTop
63-
}, [height])
73+
}, [height, isHome])
6474

6575
useEffect(() => {
6676
document.addEventListener('scroll', onScroll)
@@ -69,7 +79,6 @@ function FloatingHeader({ header }: Props) {
6979
}
7080
}, [onScroll])
7181

72-
const isHome = checkIsHome(pathname)
7382
return (
7483
<div
7584
className={cx('block')}

0 commit comments

Comments
 (0)