2014-02-05 73 views
0

我正在使用kinetic js并使用单击事件来突出显示单击时的元素。我有一个问题,直到第二次点击才会触发事件。Javascript点击不会触发,直到两次点击后

function Canvas(){ 
    this.stage; 
    this.backgroundLayer; 
} 

Canvas.prototype.init = function(w, h){ 
    this.stage = new Kinetic.Stage({ 
    container: 'container', 
    width: w, 
    height: h 
    }); 

    this.backgroundLayer = new Kinetic.Layer(); 
    this.stage.add(this.backgroundLayer); 
    this.addLayerListeners(); 
} 

Canvas.prototype.addLayerListeners = function(){ 
    this.backgroundLayer.on('click',function(evt){ 
    var shape = evt.targetNode; 
    shape.stroke('#00ff00'); 
    shape.strokeWidth('5'); 
    }); 
} 

这是正常行为吗?否则,我做错了什么?

+1

@GameAlchemist:在KineticJS行程()不实际上画出中风。它将设置strokeStyle。所以Jordy只是为随后的抽签设置strokeStyle。 :) – markE

回答

1

必须有比我看到的更多的代码。 例如,在事件监听器中,您必须在某处存在shape.draw(),layer.draw()或stage.draw()。

我使用类似的方法在一个onclick(选择)功能:

shape.setStroke('black'); 
shape.setStrokeWidth(4); 
shape.enableStroke(); 
shape.draw(); 

而且在删除行程(取消)功能:

shape.disableStroke(); 
shape.draw(); 
相关问题