如何在使用Kineticjs单击后禁用mouseout事件

时间:2014-08-04 15:35:22

标签: javascript kineticjs

我想在单击一个形状后禁用mouseout事件,并在用户单击另一个形状时恢复它。有可能吗?

我的形状在这里被命名为" parechoc"

parechoc.on('click', function() {
      this.opacity(1);
      layer.draw();
      disable_mouseout = function (){
        parechoc.off('mouseout')
      }


    });
    parechoc.on('mouseout', function() {
     this.opacity(0);
     layer.draw();
   });

1 个答案:

答案 0 :(得分:0)

警告:未经测试的代码如下!

// a variable to save the last clicked shape
var myLastClickedShape;

// a function to turn on the previously 'off' node
// and turn off the currently clicked node
function onClickableClick(node){
    // turn on mouseout stuff for the previously clicked node
    if(myLastClickedShape){
        myLastClickedShape.on('mouseout',function(){
                // do mouseout stuff
        });
    }
    // turn off mouseout for the currently clicked node
    if(node){
        this.off('mouseout');
    }
    myLastClickedShape=node;
}


// call the toggle function as required
parechoc.on('click', function() {
      onClickableClick(this);
      this.opacity(1);
      layer.draw();
}