开发者

Raphael.js how to store the name in each element?

开发者 https://www.devze.com 2023-03-03 23:26 出处:网络
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?

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'
0

精彩评论

暂无评论...
验证码 换一张
取 消