2012-05-14 205 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屬性。 –