我在每个双击阶段上添加一个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');
})