我正在使用raphel库来创建带有图像的svg。 我需要到达对象并更改图像。我可以使用数组索引获取它,但我想使用对象id。
var R = Raphael("drawing","300", "300"),
c = [ { id:"obj1",obj: R.image("https://cdn3.iconfinder.com/data/icons/free-3d-glossy-interface-icon-set/64/Options.png", 0, 0, 50, 50)} ,
{id:"obj2",obj: R.image("https://cdn3.iconfinder.com/data/icons/free-3d-glossy-interface-icon-set/64/Options.png", 100, 100, 50, 50)} ] ;
move = function(dx,dy){
this.attr({x: this.ox + dx, y: this.oy + dy});
},
start = function(){
this.ox = this.attr("x");
this.oy = this.attr("y");
this.animate({r: 70, opacity: .25}, 500, ">");
},
up =function(){
this.animate({r: 50, opacity: 1}, 500, ">");
};
R.set(c).drag(move,start,up);
c[0].obj.attr("src","https://cdn3.iconfinder.com/data/icons/free-3d-glossy-interface-icon-set/64/Circulation.png")
答案 0 :(得分:0)
c[0].node.setAttribute("id", "id_name");