Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate a fill with jQuery

Tags:

jquery

svg

I was using

element.css('fill','#000000');

and it works, but now I want to animate a fill so I wrote this:

$(element).animate({'fill': '#000000'}, 'slow');

but this doesn't work, why? I would add, I am working on SVG file.

like image 535
user3263919 Avatar asked Feb 02 '14 21:02

user3263919


2 Answers

Specifying the transition as part of the CSS may be simpler than adding another js lib:

$('#circle').css({fill: "red", transition: "2.0s"});
like image 89
patb Avatar answered Oct 11 '22 13:10

patb


JQuery does not not support the animation of SVG elements, nor does JQuery UI. You can, however, use the JQuery SVG plugin, and do the following.

$('#circle').animate({ svgFill: 'red' }, 4000);

Demo on JSFiddle

like image 21
John S Avatar answered Oct 11 '22 14:10

John S