我有这个功能
$("#canvas").on("mousedown", handleMouseDown);
但是我不知道.off
功能部件是如何工作的我已经使用了这个
$("#canvas").off("mousedown", handleMouseDown);
但似乎所有这一切都会阻止我的所有其他功能而不是那个功能。任何人都可以帮我这个功能
square.addEventListener('click', function () {
// Removed extra code
$("#canvas").off("mousedown", handleMouseDown);
context.fillStyle = color2;
context.strokeStyle = color2;
var putPoint2 = function (e) {
if (dragging2) {
var new_size = size/2;
context.fillRect(e.offsetX-new_size, e.offsetY-new_size, size, size);
}
};
engage2 = function (e) { // Made engage2() "global" to refer it in engage()
dragging2 = true;
putPoint2(e);
canvas.addEventListener('mousemove', putPoint2); // Repositioned event attachment
canvas.addEventListener('mouseup', disengage2); // Repositioned event attachment
};
var disengage2 = function () {
dragging2 = false;
context.beginPath();
canvas.removeEventListener('mousemove', putPoint2); // Added event detachment
canvas.removeEventListener('mouseup', disengage2); // Added event detachment
};
if (typeof engage === 'function') { // Added event detachment
canvas.removeEventListener('mousedown', engage);
}
canvas.addEventListener('mousedown', engage2);
});
使用.off事件时,此函数无法正常运行,而行函数仍然继续运行,这应该是关闭的位