Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda