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

265
Visualizações
How do I remove a 'pointermove' event listner with 'pointerup' event in a JavaScript class?

I'm trying to do the following:

  1. User left clicks and holds down the click, as a user moves their mouse (while holding down left click) the pointer move event will console.log "Pointer Move"
  2. On release of the left click (aka on pointerup event) I want to remove the pointer move event, therefore when a user moves their mouse it will no longer console.log "Pointer move"

I have something now in which my 'pointermove' event is always firing even after I trigger the pointer up event and remove it. You can see it in the log here - after pointer up I don't want it to fire pointer move anymore: enter image description here

Here's the code:

class Controls{
    constructor() {

        this.setControls();
        this.onPointerDown();
    }

    setControls() {
        window.addEventListener("pointerdown", this.onPointerDown);
    }

    onPointerDown(event) {
        window.addEventListener("pointermove", this.onPointerMove);
        window.addEventListener("pointerup", this.onPointerUp);
        console.log("Pointer Down");
    }

    onPointerMove(event) {
        console.log("Pointer Move");
    }

    onPointerUp(event) {
        console.log("Pointer Up");
        window.removeEventListener("pointermove", this.onPointerMove);
        window.removeEventListener("pointerup", this.onPointerUp);
    }
}

let controls = new Controls();
<div>Test</div>

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