我想在 mouseup 为 fired.But 时停止 mousemove 事件,但似乎不是 working.How 我可以这样做吗?

I want to stop the mousemove event when mouseup is fired.But it seems not working.How can i do that?

var paper = Raphael(10,10,700,500);
var backGround = paper.rect(10,10,600,400);
backGround.attr("fill", "#FFFFCC");

backGround.mousedown(function(){
    console.log("down");
    backGround.mousemove(function () {
       console.log("move");
    });
});

backGround.mouseup(function () {
    console.log("up");
   event.preventDefault();
});

触发 mouseup 事件后控制台日志 'move' 仍在工作

监听器被分配一次,然后总是被触发。你可能想设置一个标志:

 var down = false;
 backGround.mousedown(function(){
   console.log("down");
   down = true;
  });
  backGround.mouseup(function () {
    console.log("up");   
    down = false;
 });

 backGround.mousemove(function () {
   if(down){
     console.log("move");
   }
 });