Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Creación dinámica de imágenes con una vida útil aleatoria

Cada 0-2 segundos estoy creando una imagen en una ubicación aleatoria dentro de un div como este

 setTimeout("addImage()", Math.floor((Math.random() * 2000) + 1));

Quiero que estas imágenes desaparezcan entre 3 y 5 segundos después de su creación. Usando $('img').first().remove() puedo eliminar la imagen más antigua, pero quiero eliminarla específicamente en un momento posterior a su creación, no solo la más antigua. Esto será suficiente si no hay otra manera, pero no es lo ideal.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Créelos, luego establezca un tiempo de espera para ellos individualmente.

 setInterval("addImage()", Math.floor((Math.random() * 2000) + 1)); function addImage() { var tmpImg = new Image(); tmpImg.src = 'https://picsum.photos/200?' + new Date().getTime(); $('#imgs').prepend(tmpImg); tmpImg.onload = function() { setTimeout(() => { $(this).fadeOut() }, 4000); }; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id='imgs'></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!