Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda