Animate From a Variable Point with from and fromTo in GreenSock

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 4 years ago

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.

Instructor: [00:00] 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.

[00:28] 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.

[00:45] 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.

[01:12] From returns to where it started and fromTo allows you to define that ending position here.

egghead
egghead
~ 11 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today