Hello i've script which changes me text colors on interval, there is:
<script>
const txts=document.querySelector(".animate-text").children,
txtsLen=txts.length;
let index=0;
const textInTimer=3500,
textOutTimer=3300;
function animateText() {
for(let i=0; i<txtsLen; i++){
txts[i].classList.remove("text-in","text-out");
}
txts[index].classList.add("text-in");
setTimeout(function(){
},textOutTimer)
setTimeout(function(){
},textInTimer);
}
window.onload=animateText;
</script>
<script>
var i = 0;
function changeClass(){
setTimeout(function() {
txts[index].classList.add("text-out");
if(index == txtsLen-1){
index=0;
}
else{
index++;
}
animateText();
$("#animate-button").removeClass("anim" + i)
i = (i==4)?1:i+1;
$("#animate-button").addClass("anim" + (i));
}, 300)
}
setInterval(changeClass, 3500);
windows.onload=changeClass;
</script>
I need to know how can i force to start over this script after switch back to my page.
So next script for restart looks:
<script>
document.addEventListener("visibilitychange", function() {
if (document.hidden){
console.log("Browser tab is hidden")
} else {
console.log("Browser tab is visible")
//Resetowanie slidera
jQuery('#carouselExampleControls').carousel(0);
console.log('Slider został przywrócony do 1 slajdu');
// start over changeClass function here
console.log('Funkcja changeClass zaczęła działać od początku');
}
});
</script>
I need to start over changeClass() function and put it below the comment in last script