admin管理员组

文章数量:1290955

In Raphael.js, If I have a path object, I would like to reset the attribute, how to do it?

myPath.attr('M', VALUE_FOR_M)
      .attr('L', VALUE_FOR_L);

seems not working...

In Raphael.js, If I have a path object, I would like to reset the attribute, how to do it?

myPath.attr('M', VALUE_FOR_M)
      .attr('L', VALUE_FOR_L);

seems not working...

Share Improve this question edited Apr 27, 2011 at 14:41 Joachim Sauer 308k59 gold badges566 silver badges622 bronze badges asked Apr 27, 2011 at 14:37 MellonMellon 38.9k78 gold badges192 silver badges265 bronze badges 4
  • 1 @Joachim, why shouldn't I think so???? Of course I know Raphael is not jQuery. Raphael also provide attr() method to set attribute for element. If you check Raphael documentation on its official website. raphaeljs./reference.html#attr – Mellon Commented Apr 27, 2011 at 15:00
  • However, reading the linked documentation shows that M or L are not listed in the possible parameters. – Joachim Sauer Commented Apr 27, 2011 at 15:03
  • 1 Yes, that's why I ask here how to set attribute for path, since there is no reference for that. – Mellon Commented Apr 27, 2011 at 15:05
  • 1 as far as I understand M and L are not atributes of a path, they are simply elements that can exist in its specification. They can also exist multiple times so "changing their value" doesn't really make a lot of sense. Could you post an example of what you're trying to achieve? – Joachim Sauer Commented Apr 27, 2011 at 15:06
Add a ment  | 

2 Answers 2

Reset to default 6

you do it like this:

var newPath = ["M", VALUE_FOR_M_X, VALUE_FOR_M_Y, 
               "L", VALUE_FOR_L_X, VALUE_FOR_L_Y];

myPath.attr({ path : newPath });

newPath is a pathString (see SVG path string format)

To create a path, I prefer,

var myPath = paper.path(['M', M_VAL0, M_VAL1, 
                         'L', L_VAL0, L_VAL1].join(' '));
myPath.insertAfter(nodewhatever);

It makes your actions much easier to follow.

to update your path,

myPath.remove();
myPath = paper.path(['M', M_VAL2, M_VAL3, 
                     'L', L_VAL2, L_VAL3].join(' '));
myPath.insertAfter(nodewhatever);

Is this what you wanted to do?

本文标签: javascriptRaphaeljs how to set attribute for a pathStack Overflow