Клик по созданому обьекту
Доброго времени суток.
есть следующий код:
shapes = [];
createRect = function (x, y) {
shape = r.rect(x, y, 95, 25, 20);
shapes.push(shape);
text = r.text(x + 40, y + 10, "New node");
texts.push(text);
for (i = 1; i < shapes.length; i++) {
//color = Raphael.getColor();//рандомний колір
tcolor = "#4C5053";
scolor = "#BDBFC1";
fcolor = "#FCFEFF";
shapes[i].attr({ fill: fcolor, stroke: scolor, "stroke-width": 2, cursor: "move" });
texts[i].attr({ fill: tcolor, stroke: "none", "font-size": 15, cursor: "move" });
array = new Object();
array[i] = ("shapes" + i);
shapes[i].pair = texts[i];
texts[i].pair = shapes[i];
shapeLength = shapes.length;
//alert(shapeLength);
shapes[i].drag(move, dragger, up);
texts[i].drag(move, dragger, up);
};
}; //endcreaterect
document.getElementById("image").onclick = function () {
createRect(CRX, CRY);
Select();
changeC();
};
здесь я создаю , с помощью библиотеки Raphael прямоугольники при нажатии на картинку "image". как мне определить, по какому прямоугольнику я делаю клик? |
с помощью функции Select(), я вызиваю alert на клик по элементу, но вызивается только последний alert. Что тогда мне делать?
var Select = function () {
for (x in array) {
joptarray.push(shapes[x]);
//if (shapeLength == i) {
if (shapes[x]) {
shapes[x].click(function () {
selected = shapes[x];
if (selected == shapes[x]) {
alert("shape" + x);
//shapes[1].attr({ stroke: "#2C81C2", "stroke-width": 2 });
};
});
};
};
};
|
Цитата:
var Select = function () {
for (x in array) {
joptarray.push(shapes[x]);
if (shapes[x]) {
shapes[x].click(function () {
alert("shape" + x);
}
}
};
|
Спасибо всем!!! Решыл: :dance:
z++;
shapes.push(r.rect(x, y, 95, 25, 20).attr({ fill: fcolor, stroke: scolor, "stroke-width": 2, cursor: "move" }).data("shape", z)
.click(function () {
alert(this.data("shape"));
}));
|
| Часовой пояс GMT +3, время: 15:56. |