The easiest way to do this is to create a mask with a circular hole in it, and then animate the rectangle behind it. For instance:
<path fill="#fff" fill-rule="evenodd" d="M0 0 200 0 200 200 0 200ZM20 100 A80 80 0 0 0 180 100 80 80 0 0 0 20 100Z"/>
Here, these paths start with a square square of 200 units wide ( M0 0 200 0 200 200 0 200Z ), and then two arcs are used to draw a circle with a diameter of 80 units in it ( A80 80 0 0 0 180 100 80 80 0 0 0 20 100Z ) . The evenodd fill evenodd ensures that a circle is cut out of a square.
If you want the circle to fill from bottom to top, you will need to use the rotate transform:
<rect transform="rotate(180 100 100)" x="20" y="20" width="160" height="0" fill="#47f" id="fillup"/>
This rotates the coordinate system around the middle of the SVG image, so that the line grows up as you increase its height. Here I use the CSS transition to change the height of the rectangle when you hover over it. But you can use Javascript or JQuery to change the height as you wish.
Here is a working example:
svg #fillup { height:0px; transition:height 0.5s; } svg:hover #fillup { height:160px; }
<svg width="200" height="200" viewBox="0 0 200 200"> <rect x="10" y="10" width="180" height="180" fill="#eee"/> <rect transform="rotate(180 100 100)" x="20" y="20" width="160" height="0" fill="#47f" id="fillup"/> <path fill="#fff" fill-rule="evenodd" d="M0 0 200 0 200 200 0 200ZM20 100 A80 80 0 0 0 180 100 80 80 0 0 0 20 100Z"/> <circle cx="100" cy="100" r="90" fill="none" stroke="#888" stroke-width="20"/> <circle cx="100" cy="100" r="99" fill="none" stroke="#333" stroke-width="1"/> <circle cx="100" cy="100" r="80" fill="none" stroke="#333" stroke-width="1"/> </svg>
source share