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

114
Views
How to only execute onmousemove function if onmousedown is active

I don't usually use vanilla js, and I simply can't make this happen. handleTilePressed is the function I want to execute, but I don't know how to make it so that onmousemove only works if onmousedown is active.

    tile.onmousemove = function() { handleTilePressed(i) }

Any help is greatly appreciated.

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

0

You have to create a variable that could determine it the mouse was click or not:

var isMouseDown = false;
tile.addEventListener('mousedown', e => {
  isMouseDown = true
});

window.addEventListener('mouseup', e => {
isMouseDown = false
});

Now you can use this variable to determine if you are dragging or not

tile.onmousemove = function() { 
 if(isMouseDown)
 handleTilePressed(i) 

}
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!