Jump to content
Search Community

Pass the target.object to a function parameter?

Visual-Q 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

I had a question about referencing the target.object.

 

I was thinking about how I could make some pluggable functions for tweens and was wondering how I would reference the target.object to pass as a parameter to the function without having to reselect it.

 

function myFunction (target) {
  //do some calculations with target
  return something
}

// I could reselect the target object in this case using jQuery

TweenLite.to(".myObject", 1, {x: myFunction($(".myObject"))});

// But can I reference it from the tween such as this.target type of thing
                              
TweenLite.to(".myObject", 1, {x:myFunction(reference target object)});

 

Link to comment
Share on other sites

Just reference a function. The first parameter is the index, the second is the target.

TweenLite.to(".myObject", 1, { x: myFunction });

function myFunction(index, target) {
  //do some calculations with target
  return something;
}

 

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