svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.07k stars 1.08k forks source link

Tspan doesnt move when added to text #1250

Closed csae7255 closed 2 years ago

csae7255 commented 2 years ago

When creating a tspan via new SVG.Tspan().text('...') there are problems adding it to a text:

https://jsfiddle.net/csae7255/2jz30hbk/3/

csae7255 commented 2 years ago

I solved the problem.

Instead of using text.add(tspan) one has to use text.put(tspan). This also fixes the problem with newLines: text.put(tspan).newLine() works as expected.

https://jsfiddle.net/csae7255/qvpkzj1e/1/

Fuzzyma commented 2 years ago

The reason why put is working, is because put returns the element you pass to it. Since you have to call newLine on the tspan and not the text, you have to make sure that your newLine call is actually on the tspan (with put()) and not on the text (with add())