I'd like to fill a svg image with colour instead of a progress bar. I will be using this for an animated infographic.
Fill the image below slowly with green colour to show it's 30% "full".<br>
<img src="https://cdn.mediacru.sh/P-WOGKdNDiGT.svg" width="700px">
Fiddle here: http://jsfiddle.net/47ayquwq/4/
You can do this by animating a mask or a filter, and using the fakeSMIL library to polyfill for IE. Below is the filter version.
If your svg is actually just some text or a simple shape, you could also just animate inside the svg (e.g as a gradient). For IE you'd need to either add the fakeSMIL library or animate with js.
Example:
You can achieve this effect by implementing a rectangular progress bar and then masking it with the SVG. See below. However this is not a general solution. It won't work on IE because IE doesn't support CSS Masks.
You could also use the same approach as below, but instead of using CSS Masks, you could use an SVG
<mask>
or<clipPath>
element. There are plenty of other questions on here about how to use those elements. This approach will also work on IE9+.Here we have a div with a green background. And on top we have a grey div that represents the "background" of the progress bar. We are doing it this way round so we can set the "left" property of the grey div to the same value as our progress percentage.
Finally the whole thing is masked with our SVG.