diff --git a/src/header/index.jsx b/src/header/index.jsx index d93137f9..8fd2cc9c 100644 --- a/src/header/index.jsx +++ b/src/header/index.jsx @@ -1,9 +1,10 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import style from "./index.module.css"; export default function Header() { - const [scrollState, setScrollState] = useState(null); - const [positionList, setPositionList] = useState([]); + const ITEM_WIDTH = 96; // w-24 + const ITEM_GAP = 32; // gap-8 + const [scrollState, setScrollState] = useState(-1); const scrollSectionList = [ "추첨 이벤트", "차량 상세정보", @@ -11,18 +12,6 @@ export default function Header() { "선착순 이벤트", ]; - function updatePositions() { - const browserHalfWidth = window.innerWidth / 2; - const newPositionList = [browserHalfWidth - 224, browserHalfWidth - 96, browserHalfWidth + 32, browserHalfWidth + 160]; - setPositionList(newPositionList); - }; - - useEffect(() => { - updatePositions(); - window.addEventListener('resize', () => updatePositions()); - return () => window.removeEventListener('resize', () => updatePositions()); - }, []); - function gotoTop() { window.scrollTo({ top: 0, behavior: "smooth" }); } @@ -44,8 +33,11 @@ export default function Header() { } function scrollDynamicStyle() { - if (scrollState === null) return; - const position = Math.floor(positionList[scrollState]); + if (scrollState < 0) return; + + const position = Math.floor( + ITEM_WIDTH / 4 + scrollState * (ITEM_WIDTH + ITEM_GAP), + ); return { "--pos": position, }; @@ -53,11 +45,14 @@ export default function Header() { return (
- + The new IONIQ 5 -
+
{scrollSectionList.map((scrollSection, index) => (