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();
}
};
}, []);
To make the destination texts animate similarly to the counter, you need to adjust their structure and animation logic. Here's how to modify your code:
Creates a vertical stack of location groups in a scrollable container
Uses the same animation logic as the counter
Maintains the same timing and easing as other animations
Preserves the existing visual styling while adding smooth transitions
The animation will now move the locations container vertically to reveal the appropriate location group for each slide, matching the counter's animation style.