22
33import Image from 'next/image' ;
44import Cocktailcup from '../../../../public/CocktailDrop.webp' ;
5- import { useLayoutEffect , useRef } from 'react' ;
5+ import { useLayoutEffect , useRef , useState } from 'react' ;
66import gsap from 'gsap' ;
77import { ScrollTrigger } from 'gsap/all' ;
88import PassBtn from './PassBtn' ;
@@ -15,6 +15,7 @@ interface CocktailDropProps {
1515
1616function CocktailDrop ( { isDesktop = false } : CocktailDropProps ) {
1717 const containerRef = useRef < HTMLDivElement > ( null ) ;
18+ const cupRef = useRef < HTMLDivElement > ( null ) ;
1819 const logoRef = useRef < HTMLDivElement > ( null ) ;
1920 const line1Ref = useRef < HTMLDivElement > ( null ) ;
2021 const line2Ref = useRef < HTMLDivElement > ( null ) ;
@@ -43,25 +44,37 @@ function CocktailDrop({ isDesktop = false }: CocktailDropProps) {
4344 }
4445 ) ;
4546
46- // 로고 위에서 아래로 자연스럽게 등장
47- const screenWidth = window . innerWidth ;
47+ const cupElement = cupRef . current ;
48+ const logoElement = logoRef . current ;
4849
49- const viewportHeight = window . innerHeight ;
50- const isTablet = screenWidth >= 640 && screenWidth < 1024 ;
51- const isMobile = screenWidth < 640 ;
50+ if ( ! cupElement || ! logoElement ) return ;
5251
53- // 뷰포트 높이 기반으로 로고 위치 계산
54- const logoFinalY = isMobile
55- ? `-${ viewportHeight * 0.3 } px`
56- : isTablet
57- ? `-${ viewportHeight * - 0.8 } px`
58- : '210px' ;
52+ const cupRect = cupElement . getBoundingClientRect ( ) ;
53+ const logoRect = logoElement . getBoundingClientRect ( ) ;
5954
55+ // container 기준 상대 위치 계산
56+ const containerTop = containerRef . current ?. getBoundingClientRect ( ) . top || 0 ;
57+ const cupTopRelative = cupRect . top - containerTop + 10 ;
58+ console . log ( 'containerTop' , containerTop ) ;
59+ console . log ( 'cupTopRelative' , cupTopRelative ) ;
60+ console . log ( 'logoRect.height' , logoRect . height ) ;
61+
62+ const getFinalY = ( width : number ) : number => {
63+ if ( width >= 1800 ) return 200 ;
64+ if ( width >= 1400 ) return 10 ;
65+ if ( width >= 1024 ) return 295 ;
66+ if ( width >= 800 ) return 50 ;
67+ return - 235 ;
68+ } ;
69+
70+ // 내부에서 사용
71+ const finalY = getFinalY ( window . innerWidth ) ;
72+ console . log ( 'finalY' , finalY ) ;
6073 gsap . fromTo (
6174 logoRef . current ,
6275 { y : - 300 , opacity : 0 } ,
6376 {
64- y : logoFinalY , // 뷰포트 높이 기반 계산
77+ y : finalY , // 뷰포트 높이 기반 계산
6578 opacity : 1 ,
6679 duration : 3 ,
6780 ease : 'power3.out' ,
@@ -82,22 +95,22 @@ function CocktailDrop({ isDesktop = false }: CocktailDropProps) {
8295 return (
8396 < div
8497 ref = { containerRef }
85- className = "relative w-full lg:min-h-[120vh] md:min-h-[95vh] min-h-[87vh] flex flex-col lg:justify-center md:justify-center justify-end items-center mt-10 overflow-hidden"
98+ className = "relative w-full xl:min-h-[140vh] lg:min-h-[120vh] md:min-h-[95vh] min-h-[87vh] flex flex-col lg:justify-center md:justify-center justify-end items-center mt-10 overflow-hidden"
8699 id = "scroll-fixed"
87100 >
88101 { /* 대각선 줄 1 */ }
89102 < div
90103 ref = { line1Ref }
91- className = "absolute lg:top-[150px] md:top-[100px] top-[75px] left-[-50%] w-[200%] md:h-[80px] h-[50px] bg-secondary/80 rotate-[8deg] z-10"
104+ className = "absolute md:top-[100px] top-[75px] left-[-50%] w-[200%] md:h-[80px] h-[50px] bg-secondary/80 rotate-[8deg] z-10"
92105 />
93106 { /* 대각선 줄 2 */ }
94107 < div
95108 ref = { line2Ref }
96- className = "absolute lg:top-[250px] md:top-[200px] top-[150px] left-[-50%] w-[200%] md:h-[80px] h-[50px] bg-secondary rotate-[8deg] z-10"
109+ className = "absolute md:top-[200px] top-[150px] left-[-50%] w-[200%] md:h-[80px] h-[50px] bg-secondary rotate-[8deg] z-10"
97110 />
98111
99112 { /* 로고 */ }
100- < div ref = { logoRef } className = "absolute z-4 lg:w-125 md:w-115 w-65 lg:h-110 md:h-90 h-40 " >
113+ < div ref = { logoRef } className = "absolute z-4 lg:w-125 md:w-115 w-65 lg:h-60 md:h-50 h-20 " >
101114 < Image
102115 src = "/logo.svg"
103116 alt = "로고 이미지"
@@ -109,7 +122,7 @@ function CocktailDrop({ isDesktop = false }: CocktailDropProps) {
109122 </ div >
110123
111124 { /* 컵 이미지 - 모바일에서 바닥에 붙도록 */ }
112- < div className = "z-5 absolute bottom-0" >
125+ < div className = "z-5 absolute bottom-0" ref = { cupRef } >
113126 < Image
114127 src = { Cocktailcup }
115128 alt = "칵테일 컵"
0 commit comments