I have rendered several rectangulars in Raphael.js. I would like to give each of the rectangular a name, and store the name to each o开发者_如何学Cf them. How to do in Raphael?
For example:
var r1 = paper.rect(10, 10, 50, 50); //name it 'car'
var r2 = paper.rect(10, 10, 50, 50); //name it 'plane'
var r3 = paper.rect(10, 10, 50, 50); //name it 'bike'
then, in future, I can distinguish them by check the name, like r1.attr('name')=='car'
How to add new attribute to store the names then?
Why not just add an ID to the DOM object using .node
?
var r1,r2,r3;
r1 = paper.rect(10, 10, 50, 50);
r1.node.id = 'car'
r2 = paper.rect(10, 10, 50, 50);
r2.node.id = 'plane'
r3 = paper.rect(10, 10, 50, 50);
r3.node.id = 'bike'
精彩评论