I have a white inner circle and a blue outer circle.
I am trying to clip out the white inner circle to leave a blue ring.
(I know I can achieve the same thing using a single circle and a stroke, but I will be using more complex shapes in the future and want to achieve this simple task first.)
I have tried variations of the following:
const container = SVG().addTo('body').size(500, 500)
const bg = container.rect(500,500).fill('green')
// outer circle
const outerCircle = container.circle(100).fill('blue');
// inner circle
const innerCircle = container.circle(80).fill('white').center(outerCircle.cx(), outerCircle.cy());
// Clip the outer circle with the inner circle
outerCircle.clipWith(innerCircle);
However, this removes the outer circle, like so:
Can anyone tell me what I am doing wrong?
Here's a public JSFiddle: https://jsfiddle.net/j1pq7drb/


Based on the comments, you know you can use a
maskinstead of clip to achieve the desired affect.In SVG.JS, you can use
maskWith, which will look something like this:Since
Maskinherits fromSVG.Containerin SVG.JS, you can be very creative with its usage. For more complicated shapes (multiple polkadots, as an example), you can create groups inside your mask to keep everything tidy.This has an added benefit of allowing you to use group styles or group positioning to make sweeping changes.