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

128
Vistas
compare pixel postition via code on javacript

i have a problem. i'm using javascript and i'm always trying to make a faster code.

so i create an app that check the pixel position.

if your pixel pointer(red) is in the target position, the target make an action.. just press (t) to see it down

But when cross the red tile on loop to create a lot of places akk "if" dont work.

I wish he alert everytime the red takes the blue.

have any trigger to make check colision to the first object to another??

how to make a lot of if to be checked automated?

<body>
    
</body>
<script>


//ok... trying again

document.addEventListener('keydown', function(e) {
  if (e.keyCode == 84) {
    e.preventDefault();
    check();
  }
})

var position = 0

let a = document.createElement("div")

    a.style.backgroundColor = "red"       
    a.style.height          = '1px'
    a.style.width           = '1px'
    a.style.top             = position
    a.style.position        = "absolute" 

    document.body.append(a)

for (let index = 0; index < 10; index++) {

let x = index

//b = new b all the time

  let b = document.createElement("div")
      b.style.backgroundColor = "blue"  
      b.style.height          = '1px'
      b.style.width           = '1px'
      b.style.position        = "absolute"      
      b.style.top = Math.floor(Math.random(10 - 0) * 100)

      document.body.append(b)
//remember b = nem b on let all the time

function check(){

    a.style.top = position++
if (a.style.top === b.style.top ){
    alert("its ok")
}
}

}

</script>

help

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