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

262
Vistas
how to change the attribute of an object after n seconds using setTimeout

enter image description herehttps://github.com/sarang997/simulation1 Here is the simulation I am working on. You can try running the html file for it to work. There are circles colliding with each other in the simulation. Whenever a red circle collides with the green circle it changes the color of the green circle to red. Now what I want is as soon as the circle turns red I want a timer which changes its color to blue after n seconds. I am not able to achieve this.

There is a section in the shapes.js file where collision between the circles is detected and thats where I am changing the colors and thats exactly where I want the timer to start. (line 104 and 110 in shapes.js file)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is my solution to the problem you can loop it as well if you want the circle to continue changing colors (here replaced by console.log). N is here equal to seconds, it's multiplied by 1000 as setTimeout uses milliseconds by default.

   function changeColor(seconds) {
        setTimeout(function () {
                console.log('Here the circle would change color.');  
        }, seconds*1e3);
    }
    changeColor(3)
 

about 4 years ago · Juan Pablo Isaza Denunciar
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