배열로부터 여러 Raphael 오브젝트를 작성한 다음 각각에 이벤트 핸들러를 지정하는 간단한 스크립트가 있습니다. 문제는 마지막 이벤트 처리기 만 모든 개체에 대해 실행 중입니다. 여기서 내가 뭘 잘못하고 있니?각 Raphael 오브젝트에 대한 이벤트 핸들러 설정
var blockDiagram = {
"block" :[
{
"width": 100,
"height": 100,
"text" : "this is block 1",
"cx": 10,
"cy": 10,
"fill" : "blue"
},
{
"width": 100,
"height": 100,
"text" : "this is block 2",
"cx": 120,
"cy": 10,
"fill" : "yellow"
},
{
"width": 100,
"height": 100,
"text" : "this is block 3",
"cx": 230,
"cy": 10,
"fill" : "red"
}
]
};
var paper = new Raphael("holder", 700, 700)
for (i=0; i< blockDiagram.block.length; i++)
{
ms = 500;
width = blockDiagram.block[i].width;
height = blockDiagram.block[i].height;
text = blockDiagram.block[i].text;
cx = blockDiagram.block[i].cx;
cy = blockDiagram.block[i].cy;
fill = blockDiagram.block[i].fill;
p = paper.rect(cx,cy, width, height).attr({"fill": fill});
txt = paper.text(cx ,cy, text).attr({fill: 'black', stroke: "none", opacity: 0, "font-size": 15});
p.mouseover(function() {
txt.stop().animate({opacity: 1}, ms);
}).mouseout(function() {
txt.stop().animate({opacity: 0}, ms);
});
}
잘 부탁드립니다. 나는 세트로 놀고 있었고 그 일을하려고했지만 성공하지 못했습니다. – septemberbrain