Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
madwhiffery

How does gsap animate its horizontal and vertical movement?

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@ZachSaucier Thanks a bunch, That helped a lot! I made that stackoverflow post, but I wanted to make sure that this transform issue was the problem. Sorry if I posted in the wrong place.

Share this post


Link to post
Share on other sites
7 hours ago, madwhiffery said:

Sorry if I posted in the wrong place.

No problem! You're welcome to post on StackOverflow if you wish, you're just likely to not get as GSAP-y of answers :) Often times these forums get you a faster response as well.

  • Like 1

Share this post


Link to post
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.

×