Question:
I am using setInterval to slowly rotate the text content of a heading between 5 different words.
I make the text fade, change its contents, then fade back in as the new word, which will cycle on repeat.
This works perfectly, unless, I switch to a different tab in the browser and then on return to my webpage, the timing of the fading and text changing gets all out of whack, and does not work at all.
How can I make this animation stay consistent while changing back and forth between tabs?
My code:
let helloAnimationFade = wixAnimationsFrontend.timeline(
{
“repeat”: -1,
“repeatDelay”: 1000,
“yoyo”: true
}
);
$w.onReady(function () {
let greeting = $w("#text14");
helloAnimationFade
.add( greeting, {
"opacity": 0,
"duration": 1000
} );
const myArray = ["'Uy' skweyul","Tansi", "Taanishi","Weyt-k","Hello", "ÍY, SCÁĆEL
HÁLE"];
let index = 0;
setTimeout(() => {
helloAnimationFade.play();
}, 2000);
setInterval(() => {
(index>=myArray.length-1) ? index = 0 : index++;
$w('#text14').text = myArray[index];
}, 4000);
}
Product:
WIX Studio