Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda