Javascript 如何在使用Kineticjs单击后禁用mouseout事件
我想在单击一个形状后禁用mouseout事件,并在用户单击另一个形状时恢复它。可能吗 我的形状在这里被命名为“parechoc”Javascript 如何在使用Kineticjs单击后禁用mouseout事件,javascript,kineticjs,Javascript,Kineticjs,我想在单击一个形状后禁用mouseout事件,并在用户单击另一个形状时恢复它。可能吗 我的形状在这里被命名为“parechoc” 警告:未测试的代码如下 // 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
警告:未测试的代码如下
// 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();
}
谢谢,不幸的是,它不起作用。我在代码中做了一些更改。我编写了一个名为on click函数MouseClick(){onClickableClick(this);this.opacity(1);layer.draw();}的函数,这种方法称为:parechoc.on('click',MouseClick);Firebug返回:TypeError:this.off不是函数修复了一个小故障:
this.off
应该是node.off
。这很有趣,这正是我在阅读你的评论之前所做的,它可以工作,但仍然需要调整。谢谢你,马克
// 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();
}