Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 스크롤 따라 헤더바 상태 변경되는 것 구현 #69

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
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
27 changes: 11 additions & 16 deletions src/header/index.jsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import style from "./index.module.css";
import scrollTo from "../scroll/scrollTo";
import { useSectionStore } from "../scroll/store";
import { useEffect, useState } from "react";

export default function Header() {
const ITEM_WIDTH = 96; // w-24
const ITEM_GAP = 32; // gap-8
const isVisibleList = useSectionStore((state) => state.isVisibleList);
const [currentSection, setCurrentSection] = useState(0);
const currentSection = useSectionStore((state) => {
return state.isVisibleList.findIndex((value) => value === true);
});
Comment on lines +8 to +10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

const scrollSectionList = [
"추첨 이벤트",
"차량 상세정보",
"기대평",
"선착순 이벤트",
];

useEffect(() => {
const idx = isVisibleList.findIndex((value) => value === true);
setCurrentSection(idx);
}, [isVisibleList]);

function gotoTop() {
window.scrollTo({ top: 0, behavior: "smooth" });
}
Expand All @@ -37,14 +32,14 @@ export default function Header() {
}

function scrollDynamicStyle() {
if (currentSection > 0) {
const position = Math.floor(
ITEM_WIDTH / 4 + (currentSection - 1) * (ITEM_WIDTH + ITEM_GAP),
);
return {
"--pos": position,
};
}
if (currentSection <= 0) return;

const position = Math.floor(
ITEM_WIDTH / 4 + (currentSection - 1) * (ITEM_WIDTH + ITEM_GAP),
);
return {
"--pos": position,
};
}

return (
Expand Down