Так:
$('body').html(Array.from({ length: 4 }, (n, i) => `
<svg width="40px" viewBox="0 0 40 40" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle class="border" cx="20" cy="20" r="18"/>
<circle class="fill" cx="20" cy="20" r="18"/>
<text x="12" y="25" class="small">0${i + 1}</text>
</svg>
`));
const $elements = $('.fill');
function animateElem(index) {
$elements.removeClass('animation').eq(index).addClass('animation');
}
$(document).on('animationend', function(e) {
$(e.target).removeClass('animation');
const index = (1 + $elements.index(e.target)) % $elements.length;
animateElem(index);
});
$(document).on('click', 'svg', function(e) {
animateElem($elements.index($('.fill', this)));
});
.border {
fill: transparent;
stroke: #ccc;
stroke-width: 2px;
}
.fill {
fill: transparent;
stroke: #000;
stroke-width: 2px;
stroke-dasharray: 120;
stroke-dashoffset: 120;
transform: rotate(-90deg);
transform-origin: center;
}
.animation {
animation: spin 2s both linear;
}
@keyframes spin {
to {
stroke-dashoffset: 1;
}
}
??