2012-05-14 199 views
0

在我的应用程序之一,我创建与下面的代码扩展SVG路径

var points="M1180,401 S1180,476 1030 476 L100, 476"; 
createPath(points, id, name); 


    function createPath(points, id, nane) { 

       var shape = document.createElementNS(svgNS, "path"); 
       shape.setAttributeNS(null, "d", points); 
       shape.setAttributeNS(null, "class", "path"); 
       shape.setAttributeNS(null, "id", id); 
       document.getElementById("holder").appendChild(shape); 
       return id; 
} 

一个SVG路径,这将在我的SVG创建路径(命名为“持有人”)。进一步在按钮按下事件我需要延长其长度。由于SVG中有多条路径,所以我们不能拿它的点。

请帮 感谢

+2

请解释你的意思是“延长其长度” - 在任何特定的方向,变换/拉伸路径,或其他? –

+0

嗨,现在我画的线仍然是x 100,y 476 ...我需要将它延伸到x -250,y 476 – ramesh

回答

2

如果你把ID唯一,你可以用它来与document.getElementById(id)检索您的形状,并从那里修改路径。

+0

我的编号是独一无二的,您可以让我知道如何修改路径吗? – ramesh

+1

as points points'points =“M1180,401 S1180,476 1030 476 L100,476”;'你可以简单地做:'shape.setAttributeNS(null,“d”,“M1180,401 S1180,476 1030 476 L250,476 “);' 事实上,我自己的项目iscriptdesign.com参数化设计很大程度上依赖于此功能,因为它允许通过在更改滑块或输入字段后重新计算其内容来修改d属性。 –