Jump to content
GreenSock

usr1931990

animate to the original position without knowing the value

Recommended Posts

How can I animate back to the original values without knowing the value? 

Lets say my code looks like this:

gsap.set('div', {
   top: Math.floor(Math.random() * 140) + "%",
   left: Math.floor(Math.random() * 140) + "vw",
 });

 

Now in another function I just want to animate this div back to its original value (without knowing the original value) and remove the inline styles when the animation is done. 

Link to comment
Share on other sites

I'm not sure I follow the question, but you could store those values in a variable, use a yoyo tween, reverse the tween/timeline, set the progress() to 0 etc... 

 

Maybe a demo would help get some better answers for you.

 

  • Like 2
Link to comment
Share on other sites

@PointC sorry, this is what I'm trying to do!

I know that I can use a timeline and reverse it, but what if its inside an each function?

 

      $(app.$item).each(function() {
        gsap.set($(this), {
          opacity: 0,
          scale: 0,
          top: Math.floor(Math.random() * 140) + "%",
          left: Math.floor(Math.random() * 140) + "vw",
        });
        gsap.from($(this), 2, {
          opacity: 0,
          scale: 0,
          top: ????,
          left: ????,
          ease: "cubic.inOut",
        });
      });

 

Link to comment
Share on other sites

Sorry, I'm still lost. You want to grab the top/left positions from the set() and animate the elements from() those positions? That won't do anything. If the random position for top is 140 and then you animate from 140, you'll have an animation that goes from 140 to 140. See what I mean?

 

Do you have a demo for what you'd like to happen? 

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.
×