Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
How to force restart a javascript function

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

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda