[英]Konva get image ID from click event
I am trying to get the ID of the image I am clicking on by using the following code:我正在尝试使用以下代码获取我单击的图像的 ID:
theImg.on('click', function() {
alert($(this).attr('id')); //Should show 'IDofImg'
});
The Konva code is this:康瓦代码是这样的:
var theImg = new Konva.Image({
image: imageObj,
x: stage.getWidth() / 2 - 200 / 2,
y: stage.getHeight() / 2 - 137 / 2,
opacity: 0.8,
shadowColor: 'black',
shadowBlur: 5,
id: 'IDofImg',
shadowOffset: {
x: 0,
y: 0
},
startScale: 1,
shadowOpacity: 0.6,
draggable: true
});
As you see, I have id: 'IDofImg', within the making of the image but it seems not to output the needed ID.如您所见,我在制作图像时有id: 'IDofImg',但似乎没有输出所需的 ID。
It currently outputs this when clicked on:当点击它时,它当前输出:
function() {
// setting
if (arguments.length) {
this[setter](arguments[0]);
return this;
}
// getting
else {
return this[getter]();
}
}
What am I missing?我错过了什么?
You should use this.id()
because it is the Konva Image object, and not an html/javascript
object.您应该使用this.id()
因为它是 Konva Image 对象,而不是html/javascript
对象。
See also the docs: http://konvajs.github.io/api/Konva.Node.html#id另见文档: http : //konvajs.github.io/api/Konva.Node.html#id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.