在raphael中更改路径的终点

时间:2013-07-18 13:57:29

标签: jquery raphael

我正在尝试更改在raphael画布上绘制的路径的终点,但无法使语法正确。这是代码。 (函数调用arrow.attr的参数显然是错误的,但我已尝试过多种组合无效):

window.onload = function() {  
 var paper = new Raphael(document.getElementById('canvas_container'), 500, 500);  
 var circle = paper.circle(100, 100, 80);  
 var arrow = paper.path("M 100 100 l -56.5 56.5 z"); 
    arrow.attr({stroke: '#0a0', 'stroke-width': 3});

    arrow.attr({'x2':80, 'y2':0});
}  ;

raphael参考非常有限,我想知道在其他地方是否有更好的参考。

1 个答案:

答案 0 :(得分:1)

修改路径的一部分的一种方法是将路径详细信息存储在数组中,根据需要修改部件并将路径重新分配为字符串。

var paper = new Raphael(document.getElementById('canvas_container'), 500, 500),
    pathArray = ['M', 100, 100, 'l', 100, 100, 0, 100, 'z'],
    shape = paper.path(pathArray.join(' '));
// Modify the last point (0, 100) to (100, 0)
pathArray.splice(-3, 2, 100, 0);
// Reassign the path as string
shape.attr({path: pathArray.join(' ')})

希望这有帮助。

相关问题