Jump to content
Search Community

Tweening refresh issue.

Jonny 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

Hi all,


I am creating a simple interactive animation, where I have a red box inside of a container. When the user clicks inside the container, the red box moves to the cursor co ordinates, and then 'drops' to the container baseline co ordinate.


This works perfectly the first time, but on subsequent clicks, the red box jitters a bit, but effectively stays on the baseline.

In fact, if i click near the bottom of the container, the red box disappear off screen and then floats 'up' to the baseline!


Is Greensock not updating the co ordinates properly, because it's using the matrix transform?



I'm not sure if it's my amateurish code that causing problems, or a glitch in the system that i don't know about :S


Thanks for your help 

See the Pen LEemZv by anon (@anon) on CodePen

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,


The problem had to do with the fact that you are moving the starting position of the box using positions top and left but then animating the y.

When you click again, you reset the top and left to the new values you clicked at, but do not clear the y that you animated to. 


GSAP wasn't doing anything wrong, you just need to set the y value back to 0 before you animate.


Modify this function as follows:


function moveBox(){
  box.style.left = xPos +"px";
  box.style.top = yPos +"px";

  // add this next line to reset the y transform

  TweenLite.set(box, {y:0})     



Nice work though, and thanks for providing the demo.


Happy Tweening!

  • 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.
  • Create New...