why do the destination texts (for example Cyclades|Ionian Islands|Dodecanese|Saronic Gulf) not have the samee animation as the counter?
"use client";
import { useState, useEffect, useRef } from 'react';
import HomeHeader from '../components/HomeHeader/HomeHeader';
import FooterSection from '../components/FooterSection/FooterSection';
import styles from './page.module.css';
import gsap from 'gsap';
const DESCRIPTIONS = [
[
'Indonesia is a stunning archipelago',
'with diverse landscapes and rich',
'cultural heritage.'
],
[
'Greece is a stunning archipelago',
'with diverse landscapes and tall',
'impressive heritage.'
],
[
'Indonesia is the stunning archipelago',
'with diverse landscapes of rich',
'cultural and heritage.'
],
[
'Croatia is a stunning archipelago',
'and diverse landscapes with rich',
'cultural heritage ok.'
],
[
'Indonesia of the stunning archipelago',
'with diverse landscapes of the rich',
'cultural the heritage.'
]
];
// Animate counter
const animateCounter = (slideIndex: number) => {
// Calculate the height of one counter item
const counterHeight = counterRef.current?.querySelector('span')?.offsetHeight || 0;
code
if (isInitialLoad.current) {
console.log(`Initial load - setting counter position to slide ${slideIndex + 1}`);
if (counterRef.current && counterHeight > 0) {
// Start with the first item centered by offsetting by half the container height
// Since the parent has justify-content: center, we need to move up by half container height
// minus half item height to show the first item
const containerHeight = counterRef.current.parentElement?.offsetHeight || 0;
const initialOffset = (containerHeight*2);
gsap.set(counterRef.current, { y: initialOffset });
}
return;
}
// For subsequent animations, calculate position relative to the initial offset
if (counterRef.current && counterHeight > 0) {
const containerHeight = counterRef.current.parentElement?.offsetHeight || 0;
const initialOffset = (containerHeight*2);
const translateY = initialOffset - (slideIndex * counterHeight);
console.log(`Animating counter to slide ${slideIndex + 1}, translateY: ${translateY}px`);
gsap.to(counterRef.current, {
y: translateY,
duration: 0.6,
ease: "power2.out"
});
}
// Helper function to get description letter count for slide
const getDescriptionLetterCount = (slideIndex: number) => {
return DESCRIPTIONS[slideIndex].reduce((count, line) => {
return count + line.length;
}, 0);
};
// Animation functions
const animateTitleIn = (slideIndex: number) => {
// Calculate start and end indices for the current slide
let startIndex = 0;
for (let i = 0; i < slideIndex; i++) {
startIndex += DESTINATIONS[i].title.length;
}
const endIndex = startIndex + DESTINATIONS[slideIndex].title.length;
const animateTitleOut = (slideIndex: number) => {
console.log(Starting title exit animation for slide ${slideIndex});
// Calculate start and end indices for the current slide
let startIndex = 0;
for (let i = 0; i < slideIndex; i++) {
startIndex += DESTINATIONS[i].title.length;
}
const endIndex = startIndex + DESTINATIONS[slideIndex].title.length;
// Check if there are entrance animations running and kill them
const wasInterrupted = killEntranceAnimation();
if (wasInterrupted) {
console.log('Animation was interrupted - skipping exit animation, starting entrance immediately');
// If we interrupted entrance animations, skip the exit animations
// and start the new entrance animations immediately
animateTitleIn(currentSlide);
animateDescIn(currentSlide);
setPreviousSlide(currentSlide);
} else {
console.log('Normal slide change - exit animations then entrance animations');
// Normal flow: animate out previous slide, then animate in new slide
animateTitleOut(previousSlide);
animateDescOut(previousSlide);
setTimeout(() => {
animateTitleIn(currentSlide);
animateDescIn(currentSlide);
setPreviousSlide(currentSlide);
}, 300);
}
}
}, [currentSlide, previousSlide]);
// Initial animation for first slide
useEffect(() => {
const timer = setTimeout(() => {
if (titleRefs.current.length > 0 || descriptionRefs.current.length > 0) {
animateTitleIn(0);
animateDescIn(0);
setPreviousSlide(0);
// Set initial counter position after a brief delay to ensure DOM is ready
setTimeout(() => {
animateCounter(0);
isInitialLoad.current = false;
}, 50);
}
}, 100);
code
return () => clearTimeout(timer);
}, []);
// Cleanup animations on unmount
useEffect(() => {
return () => {
if (entranceAnimationRef.current) {
entranceAnimationRef.current.kill();
}
if (descEntranceAnimationRef.current) {
descEntranceAnimationRef.current.kill();
}
};
}, []);
The destination texts (Cyclades, Ionian Islands, etc.) don't have the same animation as the counter because they are not being animated at all - they're simply being shown/hidden based on the current slide index.
Looking at your code, here's the key difference:
Counter Animation:
Uses GSAP to animate with translateY transitions
Has smooth sliding motion between slides
Uses gsap.to() with easing and duration
Destination Texts:
Uses CSS display: none/block to show/hide
No animation/transition properties applied
Simply appears/disappears instantly
Here's how to fix it by adding the same animation style to the destination texts:
Or, for a more GSAP-consistent approach like your counter:
jsx
// Add a ref for the locations container
const locationsRef = useRef<HTMLDivElement>(null);
// Add to your animateCounter function or create a new one
const animateLocations = (slideIndex: number) => {
if (locationsRef.current) {
const itemHeight = locationsRef.current.querySelector('span')?.offsetHeight || 0;
const translateY = -(slideIndex * itemHeight);
gsap.to(locationsRef.current, {
y: translateY,
duration: 0.6,
ease: "power2.out"
});
}
};
// Update the locationsContainer JSX
<div className={styles.locationsContainer}>
<div
ref={locationsRef}
style={{
display: 'flex',
flexDirection: 'column',
transform: 'translateY(0px)'
}}
>
{/* ... your locations array mapping ... */}
</div>
</div>
The key is to apply the same transform-based animation that you're using for the counter, rather than using display: none/block which causes instant show/hide behavior.