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