0
我画使用jCanvas库具有这种功能在画布上几个形状:如何选择画布上的形状并返回其名称?
var factoryCounter = 1;
$(".atom").click(function() {
//get element by tag id
var AtomId = jQuery(this).attr("id");
var elementRef = "#el" + factoryCounter;
$("canvas")
.drawImage({
source:'images/' + AtomId + '.png',
layer: true,
name: "myAtom" + factoryCounter, //I need this value
fillStyle: "#36b",
strokeStyle: '#36b',
strokeWidth: 0.3,
x: 36, y: 28,
width: 45, height: 35,
radius: 100,
ccw: true,
draggable: true,
click: function(layer) {
console.log("name") //here I need to return "name", but don't know how.
}
});
factoryCounter++;
正如你可以看到每个形状都有自己独特的名字。我想创建一个函数,它返回所选形状的名称后,我用鼠标点击它。 我可以成功编辑该名称已知图形的属性,就像这样:
$("canvas").setLayer("myAtom" + 2, {
fillStyle: "#36b",
width: 100, height: 200,
rotate: 30
})
.drawLayers();
});
,但不知道如何实现shapeSelect()函数,通过点击它返回一个现有的形状的名称。
你尝试过什么? – sharakan 2013-03-01 16:23:23
主要问题是一旦创建了形状,它可能会被拖动(如可拖动:true),但无法选择。我发现选择一个形状的唯一方法是$(“canvas”)。setLayer(“myAtom”+1,{..attributes ..})。 – 2013-03-01 16:37:15
继续并编辑您的问题,然后提及。让人们知道你所尝试过的东西很重要,这样他们可以进一步帮助你。 – sharakan 2013-03-01 16:38:21