Frage

I need to make this function have the ability to have an add event listener and remove event listener

canvas2 was $('canvas') but i changed it to make it easier to use

canvas2.mousedown(function(e){handleMouseDown(e);});

because this does not have an event listener

War es hilfreich?

Lösung

Wild guess: You want

canvas2.on("mousedown", handleMouseDown);
…
canvas2.off("mousedown", handleMouseDown);

With the unnecessary anonymous function you did not have a reference to the actual passed listener, so you could not remove it any more.

when the function has been used the function needs to be disengaged

You might also consider using .one("mousedown", handleMouseDown), then.

Andere Tipps

You need to say either

canvas2.onmousedown=function(e){
     handleMouseDown(e);
});

or

canvas2.addEventListener('mousedown',function(e){
     handleMouseDown(e);
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top