I made a text-along path outside a circle, and when I clicked the next
button, the circle changes size randomly. I already made the circle transition smoothly. But I also want the text/textPath element also animating smoothly. As far as I know, SVG text can't be transitioned(?), are there any work around?
code in svelte:
<script>
let r = 100
let bez = 4*(Math.sqrt(2)-1)/3*r
let cx = 250
let cy = 200
function next() {
r = Math.random() *100
bez = 4*(Math.sqrt(2)-1)/3*r
}
</script>
<svg>
<g>
<circle cx="{cx}" cy="{cy}" r="{r*0.9}" opacity="0.05"></circle>
<path stroke="cornflowerblue"
stroke-dasharray="4"
fill="none"
d="M{cx},{cy-r}
C{cx+bez},{cy-r} {cx+r},{cy-bez} {cx+r},{cy}
C{cx+r},{cy+bez} {cx+bez},{cy+r} {cx},{cy+r}
C{cx-bez},{cy+r} {cx-r},{cy+bez} {cx-r},{cy}
C{cx-r},{cy-bez} {cx-bez},{cy-r} {cx},{cy-r}"
id="circle-text"></path>
<text fill="red">
<textPath href="#circle-text" >
Lorem Ipsum Dolor Sit Amet
</textPath>
</text>
</g>
</svg>
<button on:click={next}>
next
</button>
<style>
svg {
width:500px;
height:400px;
background-color:lightgrey;
}
circle {
transition:all 500ms ease-in-out;
}
path {
transition:all 500ms ease-in-out;
}
text {
transition:all 500ms ease-in-out;
}
textPath {
transition:all 500ms ease-in-out;
}
</style>
REPL link: https://svelte.dev/repl/fa34814ccacb4ce7a27fb40dc7c7a493?version=3.55.1