2012-04-19 7 views
0

javascriptを使用して動的に作成されたパスを埋める必要があります。私はそれのためのグラデーションを作成し、私のパスを埋めるためにそれを使用したが、何も起こらなかった。私のコードに何が問題なのですか?LinearGradient for path SVG

$('svg').prepend('<defs id="gradient"></defs>'); 
$('#gradient').append('<linearGradient id="yellow" x1="0%" y1="0%" x2="100%" y2="0%"> </linearGradient>'); 
$('#yellow').append('<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" /> <stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />'); 
$('g:nth-child(2n+1) path').attr('fill','url(#gradient)');` 

答えて

0

あなたの塗りがdefs要素を指し、直線勾配ではありません。 id = "gradient"は、linearGradient要素上にある必要があります。または、塗りつぶしURL(#yellow)を作成します。

関連する問題