我正在使用 raphael javascript svg 渲染引擎。如果我使用下面的代码
var canvas = Raphael("canvas",700,500);
var circ = canvas.circle(30,20,10);some_function(circ);
some_function
有没有办法从已创建的圆对象中提取 30、20 或 10?
最佳答案
一个可行的解决方案是使用 attr 方法
function some_function(circle){
return [circle.attr('cx'), circle.attr('cy'), circle.attr('r')]
}
返回值数组
或
function some_function(circle){
return circle.attr(['cx','cy','r']);
}
这将返回包含所有属性作为键的对象字面量。
关于javascript - 从 Raphael 对象获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1957259/