Skip to content

Commit 82254e5

Browse files
committed
[feat] 스크롤 버튼 추가
1 parent 13fd5e1 commit 82254e5

File tree

7 files changed

+76
-28
lines changed

7 files changed

+76
-28
lines changed

src/domains/main/components/3d/Scroll.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import Lottie from 'lottie-react';
22
import scroll from '@/shared/assets/lottie/ScrollDownAnimation.json';
33

4-
function Scroll() {
5-
// const style = !isDesktop
6-
// ? {
7-
// width: 45,
8-
// height: 45,
9-
// }
10-
// : {
11-
// width: 60,
12-
// height: 60,
13-
// };
4+
type Props = {
5+
ref: React.RefObject<HTMLButtonElement | null>;
6+
};
7+
8+
function Scroll({ ref }: Props) {
9+
const style = {
10+
width: 50,
11+
height: 50,
12+
};
1413
return (
15-
<div className="absolute bottom-18 left-1/2 -translate-x-1/2 rounded-full md:bg-secondary/10 bg-primary/30 z-11 md:w-[60px] md:h-[60px] w-[45px] h-[45px]">
16-
<div className="z-11">
17-
<Lottie animationData={scroll} aria-hidden loop={true} />
18-
</div>
19-
</div>
14+
<button
15+
ref={ref}
16+
type="button"
17+
onClick={() => {
18+
window.scrollBy({
19+
top: 1000,
20+
behavior: 'smooth',
21+
});
22+
}}
23+
aria-label="아래로 스크롤"
24+
className="fixed bottom-18 left-1/2 -translate-x-1/2 rounded-full bg-[#000000]/70 z-11 md:w-[60px] md:h-[60px] flex-center cursor-pointer"
25+
>
26+
<Lottie animationData={scroll} style={style} aria-hidden loop={true} />
27+
</button>
2028
);
2129
}
2230

src/domains/main/components/FinalLanding.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ function FinalLanding() {
1616
const [isDesktop, setIsDesktop] = useState(false);
1717
const [hasMounted, setHasMounted] = useState(false);
1818

19+
const scrollRef = useRef<HTMLButtonElement>(null);
20+
const [showScrollBtn, setShowScrollBtn] = useState(false);
21+
1922
useEffect(() => {
2023
const checkViewport = () => {
2124
setIsDesktop(window.innerWidth >= 1024);
@@ -61,6 +64,40 @@ function FinalLanding() {
6164
};
6265
}, [isDesktop]);
6366

67+
// scroll 버튼
68+
useEffect(() => {
69+
if (!scrollRef.current) return;
70+
71+
const tl = gsap.to(scrollRef.current, {
72+
y: 12,
73+
repeat: -1,
74+
yoyo: true,
75+
duration: 0.8,
76+
ease: 'power1.inOut',
77+
});
78+
79+
return () => {
80+
tl.kill();
81+
};
82+
}, [showScrollBtn]);
83+
84+
useEffect(() => {
85+
const updateScrollBtn = () => {
86+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
87+
const maxScroll = document.documentElement.scrollHeight - window.innerHeight;
88+
setShowScrollBtn(scrollTop < maxScroll - 5);
89+
};
90+
91+
updateScrollBtn(); // 초기 체크
92+
window.addEventListener('scroll', updateScrollBtn);
93+
window.addEventListener('resize', updateScrollBtn);
94+
95+
return () => {
96+
window.removeEventListener('scroll', updateScrollBtn);
97+
window.removeEventListener('resize', updateScrollBtn);
98+
};
99+
}, []);
100+
64101
if (!hasMounted) return null;
65102

66103
return (
@@ -91,8 +128,7 @@ function FinalLanding() {
91128
)}
92129
</div>
93130
)}
94-
95-
<Scroll />
131+
{showScrollBtn && <Scroll ref={scrollRef} />}
96132
</div>
97133
);
98134
}

src/domains/main/components/mainSlide/components/MainSlide.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function MainSlide({ isDesktop }: { isDesktop: boolean }) {
4040
ease: 'power5.out',
4141
scrollTrigger: {
4242
trigger: initialRoot.current,
43-
start: 'top 80%',
43+
start: 'top top',
4444
end: 'top top',
4545
scrub: 0.2,
4646
},
@@ -65,7 +65,7 @@ function MainSlide({ isDesktop }: { isDesktop: boolean }) {
6565
c,
6666
{
6767
x: () => stageW() - contentW(),
68-
duration: 2,
68+
duration: 1,
6969
immediateRender: false,
7070
onStart: () => c.classList.remove('invisible'),
7171
},

src/domains/main/components/mainSlide/components/mobile/MobileSlideCommunity.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function MobileSlideCommunity() {
4141
src={Community01}
4242
alt=""
4343
fill
44+
sizes="300px"
4445
priority
4546
className="object-contain object-left-bottom"
4647
/>
@@ -50,6 +51,7 @@ function MobileSlideCommunity() {
5051
src={Community02}
5152
alt=""
5253
fill
54+
sizes="600px"
5355
priority
5456
className="object-contain object-left-bottom"
5557
/>

src/domains/main/components/mainSlide/components/pc/MainSlideAbv.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ function MainSlideAbv() {
4242

4343
return (
4444
<article className="slide-content invisible w-[61%] h-full bg-primary rounded-tl-[30px] rounded-bl-[30px] p-12 flex flex-col">
45-
<div className="flex flex-col gap-[4%] h-full">
45+
<div className="flex flex-col gap-8 h-full">
4646
<p className="text-[32px] font-bold ">3</p>
47-
<div className="flex flex-col gap-5 h-full justify-between">
48-
<header className="flex flex-col gap-10">
47+
<div className="flex flex-col gap-8 h-full justify-between">
48+
<header className="flex flex-col gap-8">
4949
<h2 className="text-5xl text-white font-bold">내 알콜도수 UP</h2>
5050
<p className="text-xl leading-[1.5] font-normal text-white">
5151
5도 부터 시작하는 내 알콜도수 <br />내 참여에 따라 알콜도수 UP! <br />

src/domains/main/components/mainSlide/components/pc/MainSlideCommunity.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import Community02 from '@/shared/assets/images/community_02.webp';
55
function MainSlideCommunity() {
66
return (
77
<article className="slide-content invisible w-[71%] h-full p-12 bg-[#333333] rounded-tl-[30px] rounded-bl-[30px] flex flex-col ">
8-
<div className="flex flex-col gap-[4%] h-full">
8+
<div className="flex flex-col gap-8 h-full">
99
<p className="text-[32px] text-white font-bold">2</p>
1010
<div className="flex flex-col h-full justify-between">
11-
<header className="flex flex-col gap-10">
11+
<header className="flex flex-col gap-8">
1212
<h2 className="text-5xl text-white font-bold">함께 나누는 칵테일 이야기</h2>
1313
<p className="text-xl leading-[1.5] font-normal text-white">
1414
다양한 칵테일 레시피들을 SNS로 공유하고
@@ -17,21 +17,23 @@ function MainSlideCommunity() {
1717
</p>
1818
</header>
1919
<div className="flex flex-col w-full gap-5 mt-5" aria-hidden>
20-
<div className="relative w-[25%] rounded-2xl aspect-[0.96] overflow-hidden">
20+
<div className="relative w-full max-w-[12.5rem] rounded-2xl aspect-[0.96] overflow-hidden">
2121
<Image
2222
src={Community01}
2323
alt=""
2424
fill
2525
priority
26+
sizes="200px"
2627
className="object-contain object-left-bottom"
2728
/>
2829
</div>
29-
<div className="relative w-[70%] rounded-2xl aspect-[2.09] overflow-hidden">
30+
<div className="relative w-full max-w-[37.5rem] rounded-2xl aspect-[2.09] overflow-hidden">
3031
<Image
3132
src={Community02}
3233
alt=""
3334
fill
3435
priority
36+
sizes="600px"
3537
className="object-contain object-left-bottom"
3638
/>
3739
</div>

src/domains/main/components/mainSlide/components/pc/MainSlideTest.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const DUMMY_TEST = [
1616
function MainSlideTest() {
1717
return (
1818
<article className="slide-content invisible w-[80%] p-12 h-full bg-[#4D4D4D] rounded-tl-[30px] rounded-bl-[30px] flex flex-col">
19-
<div className="flex flex-col gap-[4%] h-full">
19+
<div className="flex flex-col gap-8 h-full">
2020
<p className="text-[32px] text-white font-bold">1</p>
2121
<div className="flex flex-col justify-between h-full">
22-
<header className="flex flex-col gap-10">
22+
<header className="flex flex-col gap-8">
2323
<h2 className="text-5xl text-white font-bold">AI기반 취향테스트</h2>
2424
<p className="text-xl leading-[1.5] font-normal text-white">
2525
복잡한 이름과 긴 설명 때문에 내 취향 칵테일 찾기 어려우셨나요? <br />

0 commit comments

Comments
 (0)