我在每次双击舞台时添加一个konvajs图像对象,如下所示。如何向以这种方式创建的konvajs图像对象添加事件监听器,是否有相当于konvajs中的标准javascript addEventListener?
stage.on('dblclick', function(e) {
//getString tell what shape to draw.
if (getString == "real-input") {
var imageObj = new Image();
imageObj.onload = function() {
var yoda = new Konva.Image({
x: Number(stage.getPointerPosition().x),
y: Number(stage.getPointerPosition().y),
image: imageObj,
width: this.width,
height: this.height,
name: "image",
draggable: true
});
// add the shape to the layer
layer.add(yoda).draw();
// add the layer to the stage
};
imageObj.src = document.getElementById("customImage").src;
}
}
});
你可以这样做,就像你使用stage
节点一样:
var yoda = new Konva.Image({
x: Number(stage.getPointerPosition().x),
y: Number(stage.getPointerPosition().y),
image: imageObj,
width: this.width,
height: this.height,
name: "image",
draggable: true
});
yoda.on('click', () => {
console.log('clicked');
})