2012-01-17 16 views
1

我試圖動態創建這個函數:試圖通過字符串函數參數爲SVG

svg.path($('#shape23'), 
path.move(333,410) 
.smoothC(333,410,333,410) 
.smoothC(217.5,415.75,217.5,415.75) 
.smoothC(333,500,333,500) 
.close(), {fill: '#CCCCCC'}); 

...與第二個參數變量值(從path.move關閉()) :

var myPath = 'path.move(333,410)'; 
myPath += '.smoothC(333,410,333,410)'; 
myPath += '.smoothC(217.5,415.75,217.5,415.75)'; 
myPath += '.smoothC(333,500,333,500)'; 
myPath += '.close()'; 

svg.path($('#shape23'), myPath, {fill: '#CCCCCC'}); 

...但我得到一個解析錯誤。

任何人都可以幫我撕下我的頭髮嗎?

回答

0

試試這個

svg.path($('#shape23'), eval(myPath), {fill: '#CCCCCC'}); 
+0

天才,謝謝你! – Mogstar 2012-01-17 18:28:32

0

我應當與SVG構造玩,我使用XML ...

path = Document.createElementNS('http://www.w3.org/2000/svg', 'path'); 
path.setAttribute('id', '#shape23'); 
path.setAttribute('d', 'm33,410 c333,410 217.5,415.75 333,500z'); 
path.setAttribute('fill', '#CCCCCC'); 

不知道路徑度量的,但你可以解決這些問題。