@@ -25,6 +25,8 @@ export function HeroSection() {
2525 const wrapperRef = useRef < HTMLDivElement | null > ( null )
2626 const wrapperRef2 = useRef < HTMLDivElement | null > ( null )
2727 const targetRef = useRef < HTMLDivElement | null > ( null )
28+ const tlRef = useRef < gsap . core . Timeline | null > ( null )
29+ const resizeRafRef = useRef < number | null > ( null )
2830
2931 useEffect ( ( ) => {
3032 if ( isTransitioning ) {
@@ -39,18 +41,14 @@ export function HeroSection() {
3941 const wrapperElements = [ wrapperRef . current , wrapperRef2 . current ]
4042 const targetEl = targetRef . current
4143
42- let tl : gsap . core . Timeline
43- let resizeRaf : ReturnType < typeof raf >
44-
4544 function flipTimeline ( ) {
46- // eslint-disable-next-line @typescript-eslint/no-misused-promises
47- if ( tl ) {
48- tl . kill ( )
45+ if ( tlRef . current ) {
46+ tlRef . current . kill ( )
4947 gsap . set ( targetEl , { clearProps : 'all' } )
5048 }
5149
5250 // Use the first and last wrapper elements for the scroll trigger.
53- tl = gsap . timeline ( {
51+ tlRef . current = gsap . timeline ( {
5452 scrollTrigger : {
5553 trigger : wrapperElements [ 0 ] ,
5654 start : 'center center' ,
@@ -79,7 +77,7 @@ export function HeroSection() {
7977 const offset = nextDistance - thisDistance
8078
8179 // Add the Flip.fit tween to the timeline.
82- tl . add (
80+ tlRef . current . add (
8381 Flip . fit ( targetEl , nextWrapperEl , {
8482 duration : offset ,
8583 ease : 'none'
@@ -90,8 +88,11 @@ export function HeroSection() {
9088 }
9189
9290 window . addEventListener ( 'resize' , ( ) => {
93- raf . cancel ( resizeRaf )
94- resizeRaf = raf ( flipTimeline )
91+ if ( resizeRafRef . current ) {
92+ raf . cancel ( resizeRafRef . current )
93+ }
94+
95+ resizeRafRef . current = raf ( flipTimeline )
9596 } )
9697
9798 flipTimeline ( )
@@ -144,7 +145,15 @@ export function HeroSection() {
144145 November 2025
145146 </ motion . p >
146147
147- < motion . div className = 'block md:hidden' >
148+ < motion . div
149+ className = 'block md:hidden'
150+ initial = { { opacity : 0.5 , scale : 0 , translateY : - 30 } }
151+ animate = { { opacity : 1 , scale : 1 , translateY : 0 } }
152+ transition = { {
153+ duration : 0.4 ,
154+ scale : { type : 'tween' , visualDuration : 0.4 }
155+ } }
156+ >
148157 < MotionImage
149158 src = { HeroImage }
150159 alt = 'Da Nang Villa'
0 commit comments