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

224
Vistas
If I have multiple divs on my screen, and on click they all move to the right of the webpage. How can I determine which reached first?

I have a parent class of animal and multiple subclasses like, leopard, caracal and cheetah. They are placed on the web page once their respective buttons are clicked and when my button start is clicked, they all move at random times (milliseconds) to the right of the webpage. How would I determine which one was the first to arrive at the right of the page?

This is how I get the full width of the web page:

var trackWidth = $(window).width();

The function bellow is invoked one the start button on the html page is clicked, every child class or animal in this case has this function

Leopard.prototype.getReady = function() {
var raceTime = Math.floor((Math.random() * 5000) + 1)
this.$node.animate({
    left: trackWidth,//This move the animal the width of the webpage(In this case, the track)
}, raceTime)
}

This is an array that stores each instance of an Animal:

var arr = window.animals = [];

This function iterates through the array and calls the getReady of each child class

 var start_btn = document.querySelector(".startRace");
    $(start_btn).click(function() {
        arr.forEach(function(animal) {
            animal.getReady()
        })
    })

So yes, my question is if four animals were racing across the width of the webpage, how would I be able to print which one was first or has one the race?

(Please inform me if the question needs to be updated or redone)

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