Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Yannis Yannakopoulos

Animate text on an SVG path

Go to solution Solved by GreenSock,

Recommended Posts

Hello!

 

I want to layout some text on an SVG path and have an animation play in a loop, on hover. On mouse out, the text should go back to its initial state. I used SplitText and the MotionPath plugins in my CodePen and it looks kind of what i want, but i have the following issues:

 

Timeline related:

  • The intended initial layout, is the one you'll see if you comment out addPause (line 44). I thought i'd probably need to change the startTime of the timeline, but that's not working. What am i missing?
  • On mouseout, i'd like to tween the timeline to its initial state (the corrected initial layout), but again not working as expected. Any ideas?

 

SplitText & MotionPath related:

  • Right now the letter & word spacing is off. It's tight to the stagger values. So how can i maintain the default ones? (This animation is intended to work with words of different lengths).
  • Is there a callback i could use onResize that would re-calculate the correct position of the letters? 

 

Any help in any of the above would be much appreciated :)

 

Thanks in advance

See the Pen abZdZzP by neundex (@neundex) on CodePen

Link to comment
Share on other sites

 

Hey @Yannis Yannakopoulos

 

You could set your timeline to reversed initially and on mouse-events, you could check for the reversed state, and depending on that, tell the timeline what to do, like so

 

tl.reversed() ? tl.play() : tl.reverse();

 

Does that come close to what you thought of?

 

See the Pen 435b6ed383676fc46558b2840117e390 by akapowl (@akapowl) on CodePen

 

 

  • Like 3
Link to comment
Share on other sites

15 minutes ago, akapowl said:

Does that come close to what you thought of?

 

Thank you @akapowl i did try .reverse(), but i don't think it's the way to go for this one. If you hover the element and stay for 2 loops, reverse will play backwards twice.

Link to comment
Share on other sites

Hey Yannis. With this level of control it's probably best to set up a "real" tween (not stagger) for each letter using a loop and set up the start and end of the motion paths based on what you want the offset to be. Something like this:

See the Pen VwjKPWV?editors=0010 by GreenSock (@GreenSock) on CodePen

 

(It seems that MotionPathPlugin doesn't like numbers with a lot of repeating numbers, hence why I had to add the rounding to 2 decimal places. @GreenSock not sure if we want to change that or not)

  • Like 3
Link to comment
Share on other sites

 

Nice solution @ZachSaucier

 

Just as a sidenote:

For me, your solution did not apply the mouse-events properly.

 

I had to change this 

 

$svg.on('mouseenter, mouseleave', () => tl.reversed() ? tl.play() : tl.reverse());

 

to that

 

$svg.on('mouseenter', () => tl.reversed() ? tl.play() : tl.reverse());
$svg.on('mouseleave', () => tl.reversed() ? tl.play() : tl.reverse());

 

 

See the Pen ffe2fe95c06831a422d6400350954ad2 by akapowl (@akapowl) on CodePen

 

 

 

  • Like 3
Link to comment
Share on other sites

2 hours ago, ZachSaucier said:

With this level of control it's probably best to set up a "real" tween (not stagger) for each letter using a loop and set up the start and end of the motion paths based on what you want the offset to be.

Makes perfect sense Zach, many thanks for this! 

 

Any ideas on maintaining the correct letter & word spacing?

Link to comment
Share on other sites

  • Solution
2 hours ago, ZachSaucier said:

(It seems that MotionPathPlugin doesn't like numbers with a lot of repeating numbers, hence why I had to add the rounding to 2 decimal places. @GreenSock not sure if we want to change that or not)

Very interesting - this was caused by tiny math issues related to binary systems: 

start: 2.8 / 5, // (0.5599999999999999)
end: 2.8 / 5 + 1, // (1.56)

Thus those values were interpreted as slightly more than one iteration around. That should be resolved in the next release which you can preview at https://assets.codepen.io/16327/MotionPathPlugin.min.js

 

Here's how I'd probably do it (I'm not a fan of the instant/jarring change in direction): 

See the Pen 5b5b47f9fe28ff287db07274154199dd?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Does that help? 

  • Like 4
Link to comment
Share on other sites

  • 2 weeks later...
On 10/20/2020 at 9:31 PM, GreenSock said:

Does that help? 

That's really cool Jack and it does help indeed 😀

 

Only point being that SplitText doesn't follow the right letter & word spacing of the initial phrase. 

Would you say that this is something i could tackle with CSS or SplitText settings, or is it a timeline issue? 

Link to comment
Share on other sites

4 hours ago, Yannis Yannakopoulos said:

Only point being that SplitText doesn't follow the right letter & word spacing of the initial phrase. 

Would you say that this is something i could tackle with CSS or SplitText settings, or is it a timeline issue? 

That's just related to how you're setting up the start/end values. That's totally unrelated to GSAP and beyond the scope of these forums, so I don't have time to figure it all out for you but it should be possible to build an algorithm for that. If someone else wants to chime in and help out for free, great. Otherwise, you may need to hire someone to do that consulting work. Feel free to reach out to us privately if you'd like to explore that with GreenSock. 

 

Good luck with the project. 

  • Like 2
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.
×