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

125
Views
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
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!