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

301
Vistas
¿Cómo colocar divs verticalmente al hacer clic en el botón?

Tengo un programa que se supone que es una carrera entre cuatro "animales", que en este caso están representados por divisiones cuadradas. Sin embargo, cuando agrego un animal, se coloca aleatoriamente debido a esta función:

 var animal = new animalMakerFunction( $("body").height() * Math.random(), $("body").width() * Math.random(), Math.random() * 1000 );

Esta es la clase padre, la clase Animal.

 var Animal = function(top, left, timeBetweenSteps) { this.$node = $('<span class="animal"></span>'); this.top = top; this.left = left; this.timeBetweenSteps = timeBetweenSteps; this.step(); this.setPosition(this.top, this.left); }; Animal.prototype.step = function() { setTimeout(this.step.bind(this), this.timeBetweenSteps); }; Animal.prototype.setPosition = function(top, left) { this.position = { top: top, left: left }; this.$node.css(this.position); };

Esta es una clase que hereda de la clase animal.

 var Caracal = function(top, left, timeBetweenSteps) { Animal.call(this, top, left, timeBetweenSteps); }; Caracal.prototype = Object.create(Animal.prototype); Caracal.prototype.constructor = Caracal; Caracal.prototype.step = function() { Animal.prototype.step.call(this); this.$node.css("background-color", "purple") };

Entonces, ¿cómo alinearía los animales (divs) verticalmente (en diferentes filas) con el clic de un botón?

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

0

Puede agregar clase para todos los animales y luego usar

 document.getElementByClass(".animal").style.left="0px"
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