1+ import FadeInDiv from '@/components/FadeInDiv' ;
2+ import { useState , useRef , useEffect } from 'react' ;
3+
14function MainSectionList ( { headText, semiHeadText, imgData, backgroundImage } ) {
25 const { src, alt } = imgData ;
36
@@ -8,28 +11,66 @@ function MainSectionList({ headText, semiHeadText, imgData, backgroundImage }) {
811 mainSectionBackgroundImage3 : 'bg-mainSectionBackgroundImage3' ,
912 } ) [ name ] || '' ;
1013
14+ const targetRef = useRef ( null ) ; // 관찰할 DOM 요소
15+ const [ triggered , setTriggered ] = useState ( false ) ; // 트리거 상태 관리
16+
17+ useEffect ( ( ) => {
18+ const observer = new IntersectionObserver (
19+ ( [ entry ] ) => {
20+ if ( entry . isIntersecting ) {
21+ setTriggered ( true ) ; // 트리거 상태를 true로 변경
22+ observer . disconnect ( ) ; // 한 번 실행 후 옵저버 정지
23+ }
24+ } ,
25+ {
26+ root : null , // 뷰포인트 기준 (null은 브라우저의 뷰포인트를 기준으로 함)
27+ threshold : 0.15 , // 요소가 10%만 뷰포인트에 들어와도 트리거
28+ }
29+ ) ;
30+
31+ if ( targetRef . current ) {
32+ observer . observe ( targetRef . current ) ; // 타겟 요소 관찰 시작
33+ }
34+
35+ return ( ) => {
36+ if ( targetRef . current ) {
37+ observer . disconnect ( ) ; // 컴포넌트 언마운트 시 옵저버 정지
38+ }
39+ } ;
40+ } , [ ] ) ;
41+
1142 return (
12- < div className = "relative flex flex-col items-center overflow-hidden" >
43+ < div
44+ className = "relative flex flex-col items-center overflow-hidden"
45+ ref = { targetRef }
46+ >
1347 { /* 배경 이미지 */ }
14- < div
48+ < FadeInDiv
49+ triggered = { triggered }
1550 className = { `z-0 absolute top-[90px] tablet:top-[45px] pc:top-[90px] w-[768px] h-[768px] pc:w-[900px] pc:h-[900px] bg-cover bg-center ${ getBackgroundClass ( backgroundImage ) } ` }
1651 >
1752 < div className = "z-2 absolute inset-0 bg-radial-black" > </ div >
18- </ div >
19-
53+ </ FadeInDiv >
2054 { /* 콘텐츠 */ }
21- < div className = "flex flex-col z-10 mt-[60px] mb-[240px] items-center gap-4 text-center" >
22- < h2 className = "text-[16px] leading-[20px] font-medium text-[#D2C030]" >
23- { headText }
24- </ h2 >
25- < h1 className = "text-[24px] leading-[28px] font-bold whitespace-pre-line" >
26- { semiHeadText }
27- </ h1 >
28- < img
29- src = { src }
30- alt = { alt }
55+ < div className = "flex flex-col z-10 mt-[60px] mb-[120px] items-center gap-4 text-center" >
56+ < FadeInDiv triggered = { triggered } delay = "0s" >
57+ < h2 className = "text-[16px] leading-[20px] font-medium text-[#D2C030]" >
58+ { headText }
59+ </ h2 >
60+ < h1 className = "text-[24px] leading-[28px] font-bold whitespace-pre-line" >
61+ { semiHeadText }
62+ </ h1 >
63+ </ FadeInDiv >
64+ < FadeInDiv
65+ triggered = { triggered }
3166 className = "mt-[60px] w-[240px] h-[520px] tablet:w-[200px] tablet:h-[432px] pc:w-[320px] pc:h-[692px]"
32- />
67+ >
68+ < img
69+ src = { src }
70+ alt = { alt }
71+ className = "w-[240px] h-[520px] tablet:w-[200px] tablet:h-[432px] pc:w-[320px] pc:h-[692px]"
72+ />
73+ </ FadeInDiv >
3374 </ div >
3475 </ div >
3576 ) ;
0 commit comments