Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

partial fill a SVG background

Tags:

jquery

svg

fill

New to using SVG.

Is it possible to partially fill an SVG background on a mouse event using Jquery?

The code below fills the entire SVG. Im just curious if you can fill maybe 5% of that at a time?

so for example:

   $('#button').on('click', function(){
   circle1animate();
   });


   function circle1animate(){
       $('#circle1im').css('fill','#000');                          

    }

JSFIDDLE

Thanks

like image 641
gregdevs Avatar asked Jun 08 '26 04:06

gregdevs


1 Answers

Use a linearGradient in the SVG.

In the SVG:

<linearGradient id="grad">
    <stop offset="0%"  stop-color="red"/>
    <stop offset="0%" stop-color="transparent"/>
</linearGradient>

and in the Javascript:

$('#grad stop').attr('offset',offset+'%');

Like this JSFiddle example.

like image 56
Robbie Wxyz Avatar answered Jun 10 '26 18:06

Robbie Wxyz