Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Animate From a Variable Point with from and fromTo in GreenSock

    John LindquistJohn Lindquist

    GreenSock also supports the ability to animate from a variable point to the current point. If you think to starts at a static point and moves to a variable point then from essentially does the opposite. fromTo supports the scenario where both points are variables and requires passing in a "from" set of properties and a "to" set of properties.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: Set up an event listener on the document. Add event listener. When you click, we're going to grab the event and use TweenMax. We'll use from instead of to, but still target the element of box, say one second. We'll grab the X and Y off of the event -- so X and Y from the event -- so that the event XY gets passed in down here.

    When I hit save here and click, you'll see the box comes to the mouse and returns back to where it started. It's tweening from where I click, so click it tweens from where I click, click tweens from where I click.

    There's also fromTo which behaves very similarly. It allows you to pass in another set of options, where I'll say X500, Y500. Now it'll tween from where I click to 500 and 500. Click, and now it goes down there. Click, now it goes down there. Click, and down, and to the right.

    From returns to where it started and fromTo allows you to define that ending position here.