Jump to content
Search Community

How does gsap animate its horizontal and vertical movement?

madwhiffery test
Moderator Tag

Recommended Posts

I'm kind of a beginner in web development, so I'm not entirely sure if I'm on the right track here, but I've been trying to create cursor trails for some movable text. You can see the effect in the pen, and it seems to work. However I've been wanting to try and center the text to the cursor, which I just can't seem to do. Most video tutorials suggest using transform: translate(-50%,-50%), which seems to work for them, but not for me. I've attempted to do this moving text effect with jQuery and pure js, but that produces some really choppy animation- especially on chrome and safari. Gsap seems to consistently perform well across browsers, so I've been trying to get this to work.

 

So I've been experimenting, and have found myself confused here- does x: e.clientX and y: e.clientY both animate using the translate3D css property? Is this overwriting transform: translate(-50%,-50%) ? Is there a simple way to fix this, or do I have to resort to figuring out some math on the js side of things? Thanks in advance.

See the Pen oNjgjrG by teab0t (@teab0t) on CodePen

Link to comment
Share on other sites

Hey madwhiffery. The post on StackOverflow already shows one solution so I'm curious why you're posting here. But I'm glad you did because we don't recommend setting transforms in CSS for elements being animated by GSAP :) 

 

12 minutes ago, madwhiffery said:

Most video tutorials suggest using transform: translate(-50%,-50%), which seems to work for them, but not for me.

Yes, this is because the transform is getting overwritten. See the most common GSAP mistakes for more info.

 

Just set the offset using GSAP's xPercent and yPercent properties before animating:

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

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