문제

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

도움이 되었습니까?

해결책

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.

다른 팁

You need to say either

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

or

canvas2.addEventListener('mousedown',function(e){
     handleMouseDown(e);
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top