2012-10-12 125 views
2

其次,我有一个使用raphaeljs lib的不同路径的SVG窗体转换。
我想通过调用raphaeljs 2.1.0 => getById(id)的函数来获得路径。
但Chrome或Firefox告诉我,没有函数getById!我不明白为什么?function getById Raphael js

这一块我的代码:

rsrGroups = [path_c_trsp,path_i_trsp,path_l_trsp,path_o_trsp]; 
len = rsrGroups.length; 

for(var i = 0; i < len; i++){ 
    var el = rsrGroups[i]; 

el.mouseover(function() { 
    rsrGroupsMin.forEach(function(el){ 
     var getPath = el.getById('el.id'); // here is the method called ! 
     alert(getPath); 
     el.animate({opacity: 0.5},350,function() {}); 
     rsrGroups2.forEach(function(tri){ 
      tri.animate({opacity: 0.5},350,function() {}); 
     }); 
    }); 
    this.animate({opacity: 1},350,function() {}); 
}); 
} 

这是由Chrome给出的错误:

Uncaught TypeError: Object Raphaël’s object has no method 'getById'

我尝试不同的事情,但没有一件作品:/

回答

2

getById是纸对象上的方法,而不是元素,即

var paper = Raphael(10, 50, 320, 200); 
paper.getById('id') 

或者如果您无法访问纸张变量,您可以调用el.paper.getById

+0

谢谢你,我在看完我的代码后自己找到它^^ 我必须做var getPath = ** rsr **。getById(this.id); – Glou94

-1

您的意思是el.getElementById('el.id')