diff --git a/src/header/index.jsx b/src/header/index.jsx index d3ddbd15..d93137f9 100644 --- a/src/header/index.jsx +++ b/src/header/index.jsx @@ -1,9 +1,8 @@ -import { useEffect, useRef, useState } from "react"; +import { useEffect, useState } from "react"; import style from "./index.module.css"; export default function Header() { const [scrollState, setScrollState] = useState(null); - const scrollListRef = useRef([]); const [positionList, setPositionList] = useState([]); const scrollSectionList = [ "추첨 이벤트", @@ -12,13 +11,17 @@ export default function Header() { "선착순 이벤트", ]; - useEffect(() => { - const newPositionList = scrollListRef.current.map((ref) => { - const pos = ref.getBoundingClientRect(); - return pos.left + ref.offsetWidth / 2 - 25; - }); + function updatePositions() { + const browserHalfWidth = window.innerWidth / 2; + const newPositionList = [browserHalfWidth - 224, browserHalfWidth - 96, browserHalfWidth + 32, browserHalfWidth + 160]; setPositionList(newPositionList); - }, [scrollState]); + }; + + useEffect(() => { + updatePositions(); + window.addEventListener('resize', () => updatePositions()); + return () => window.removeEventListener('resize', () => updatePositions()); + }, []); function gotoTop() { window.scrollTo({ top: 0, behavior: "smooth" }); @@ -49,20 +52,17 @@ export default function Header() { } return ( -
- +
+ The new IONIQ 5 -
+
{scrollSectionList.map((scrollSection, index) => (
{ - scrollListRef.current[index] = section; - }} onClick={() => onClickScrollSection(index)} - className={`flex items-center cursor-pointer ${scrollState === index ? "text-black" : "text-neutral-300"}`} + className={`flex justify-center items-center w-24 cursor-pointer ${scrollState === index ? "text-black" : "text-neutral-300"}`} > {scrollSection}
@@ -76,7 +76,7 @@ export default function Header() {