Jump to content
Search Community

Is there a way to animate <tspan> of an svg?

Gatts test
Moderator Tag

Recommended Posts



(I am not sure if this is the right way of attaching a video here)

 

What i've tried to do is separate each <text> into <tspan> 's letter. Each of that letter would have the same classname. I have encountered a problem where translate properties are not working on the tspan but other animation properties are working like opacity. Based on my research, it is also not possible to use translate properties on <tspan> elements. So, how would you guys suggest I do this effect? 

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 

 

Once we see an isolated demo with your attempt, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Yes, your research is correct. tspans don't accept css transform values. However they do have x, y, dx, dy, and rotate attributes that can be animated, but they bring along their own baggage. By baggage, I mean they are a nightmare to work with.

 

Consider the following example

See the Pen WNzNLwz?editors=1010 by snorkltv (@snorkltv) on CodePen

 

Note how:

  • moving the "e" moves all the letters that follow.
  • the "o" rotates around the lower left corner.
  • if you remove  y="100" on the "e" <tspan> then the animation starts at y:0 which is above the viewport.
  • if you uncomment the seemingly simple stagger on the last line then the animation gets totally mangled 

 

I'm currently working on a lesson video explaining all that (and more), but for the best results you need to:

 

  • Break your text apart into individual <path> outlines (my preference)
  • OR create individual <text> elements for each character and manually position them where they should be. 

This is acceptable for a few words but if you have many lines of text you may want to just animate each line instead of each character.

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...