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
How to have a function execute from mousedown until mouseup or mouseleave

I am making a custom element. I want to have a function that continuously does stuff from when the mouse is pressed down on the element until either the button is released or the mouse leaves the element. My issue is that it seems that while I'm holding the mouse down no other events are firing.

This only seems to be an issue in FireFox as it works basically as intended in Chrome when I tested it. Any tips on how I could make it work in FF? Relevant code snippets below:

// attaching event listeners in connectedCallback
connectedCallback() {
  /*
    Some other code before...
  */
  this.addEventListener('mousedown', this._onMouseDown)
  this.addEventListener('mouseenter', this._setMouseOnTrue)
  this.addEventListener('mouseup', this._setMouseOnFalse)
  this.addEventListener('mouseleave', this._setMouseOnFalse)
}

_setMouseOnTrue(event) { this._mouseOn = true}
_setMouseOnFalse(event) { this._mouseOn = false }
_onMouseDown(event) {
  if (event.button === 0) {
    this._setMouseOnTrue(event)
    this.func()
  }
}

func() {
  if (this._mouseOn) {
    this._privateFunc()
    setTimeOut(this.func.bind(this), time)
  }
}
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!