Jump to content
Search Community

Tracking Position of a Text Span with Javascript

Web Bae test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hello Powerful People!

 

I'm curious why my pen doesn't behave like I would expect - I was hoping that the red element would track the position of the blue text span on window resize. It works great on load but not on the window resize event.

 

I could easily solve this by nesting the red element as a child of the blue span, but it doesn't work for the animation I'm working on. I'm trying to reverse engineer the text animation in second section of latest showreel addition: https://www.epic.net/ - from what I can tell the codepen is pretty similar to their setup but I can't get the responsiveness to work.

 

On another note I set the whole thing up (very responsively) with GSAP Flip but then wasn't able to control the paths - the elements would just straight line it for their destination state. A side question to this one - is there a way to control the path traveled during a flip animation? (i.e. similar to how Carl achieves curved motion with combined eases in this pen:

See the Pen dyoxXaQ by snorkltv (@snorkltv) on CodePen

)

 

Thank you!

See the Pen RwBzexQ by learyjk (@learyjk) on CodePen

Link to comment
Share on other sites

Heya mate! Sorry could you give this another go at explaining? What are you trying to do with the red dot? Position it over the blue word? (I can't find the animation in the link you added)

---


In terms of a curved path though, TIL! I didn't know you could pass in different eases with FLIP! But you can, look at this!

 

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

  • Like 1
Link to comment
Share on other sites

Howdy 🤠

 

Let me have another go at explaining myself 😅 - and thanks for having a look.

 

I'm trying to recreate the text animation seen in second section (About) on https://www.epic.net/

 

I've gotten really far with it! You can find my version here: https://epic-agency-text.webflow.io/

 

The problem I'm having is that the text that animates doesn't track its proper position when I resize the browser. If I could fix that one thing then everything would be gravy!  🦃

 

The codepen below is my attempt at a minimum example - I'm trying to get the red text to track the position of the blue text on browser resize event. Works great on initial load but not on resize. Something about when the text "reflows" gets the positioning all messed up.

 

 

Thanks!

 

 

Link to comment
Share on other sites

  • Solution

Cool effect!

 

Here's one other option that uses transforms instead of top/left (I just always prefer transforms since they don't affect layout/reflow and they can handle sub-pixel rendering): 

See the Pen ZEjgbRy?editors=0110 by GreenSock (@GreenSock) on CodePen

 

But in this case it probably doesn't matter much if you use top/left. Note that I had to switch the display to inline-block instead of inline because browsers won't render transforms on inline elements. 

 

No need to do two different .set() calls either :)

 

Does that help? 

  • Like 3
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...