我在每次双击舞台时都添加一个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;
}
}
});
答案 0 :(得分:2)
您可以完全按照对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');
})