import { preloadFonts } from '../utils.js'; // Splitting.js // Calling the Splitting function to split the text into individual words/characters, const splittingOutput = Splitting(); // .content__text elements const texts = [...document.querySelectorAll('.content__text')]; // Let's define the position of the current text let currentTextPos = 0; // Check if there's an animation in progress let isAnimating = false; // Add class current to the "current" one texts[currentTextPos].classList.add('content__text--current'); // switch between texts const switchTexts = () => { if ( isAnimating ) return false; isAnimating = true; const upcomingTextPos = currentTextPos ? 0 : 1; // All current text words const currentWords = splittingOutput[currentTextPos].words; // All upcoming text words const upcomingtWords = splittingOutput[upcomingTextPos].words; gsap .timeline({ defaults: { duration: 0.05, ease: 'expo' }, onComplete: () => { // Update currentTextPos currentTextPos = upcomingTextPos; isAnimating = false; } }) .fromTo(currentWords, { willChange: 'transform', scaleY: 1 }, { duration: .5, ease: 'back.in(3)', scaleY: 0, stagger: { each: 0.03, from: 'start' }, onComplete: () => { texts[currentTextPos].classList.remove('content__text--current'); } }, 0) .fromTo(upcomingtWords, { willChange: 'transform', scaleY: 0, }, { onStart: () => { texts[upcomingTextPos].classList.add('content__text--current'); }, duration: .7, ease: 'elastic.out(0.7)', scaleY: 1, stagger: { each: 0.025, from: 'start' } }, '>-=0.65') }; document.querySelector('.trigger').addEventListener('click', switchTexts); // Start preloading fonts preloadFonts('wah6sge').then(() => { // Once fonts are loaded, remove the 'loading' class from the body, ending the loading state document.body.classList.remove('loading'); });