Jump to content
Search Community

tween to absolute coordinate

Woj test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hey everyone. I have an object that follows the mouse.  On click, id like to object to tween to a certain x,y value from whatever the mouses current position is. Right now in my codepen on click the circle object tweens to X:100 from where the mouse is positioned. I need it to tween to a specific position in its parent. Any ideas? 

See the Pen dzWgyM?editors=1111 by stevewojcik (@stevewojcik) on CodePen

Link to comment
Share on other sites

Hi @Woj

 

Using x/y instead of left/top is usually better as the animation will be smoother and it doesn't force the browser to recalculate the layout.

 

So here's another way to approach this. I positioned the circle outside the main div to make calculations easier. And instead of creating a tween on every mouse move, I'm using the ModifiersPlugin instead. 

 

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

 

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