Jump to content
GreenSock

dwillis

How to pass element to onComplete function?

Recommended Posts

Hi!

I'm new to GSAP (and loving it!) and I'm trying to figure out how to pass a reference to the DOM element I'm tweening to the onComplete function. I've tried the following:

TweenLite.to($("#content li")[i], 1, {top:"150%", onCompleteParams:[lmnt], onComplete:function(){
                console.log(lmnt); //Uncaught ReferenceError: lmnt is not defined
            }}); 

TweenLite.to($("#content li")[i], 1, {top:"150%", onCompleteParams:["lmnt"], onComplete:function(){
                console.log(lmnt); //Uncaught ReferenceError: lmnt is not defined
            }});

TweenLite.to($("#content li")[i], 1, {top:"150%", onComplete:function(){
                console.log(this); //appears to be TweenLite object--instanceof HTMLElement is false
            }});

TweenLite.to($("#content li")[i], 1, {top:"150%", onCompleteScope:this, onComplete:function(){
                console.log(this.toString()); //[object Window]
            }});


How can I pass reference the DOM element that just finished tweening? I'm trying to reset the top parameter to it's starting value so the next time it tweens it will be starting from the beginning instead of the end. Halp?

Thanks!

Link to comment
Share on other sites

Hi dwillis  :)

 

pls try : this.target

  • Like 6
Link to comment
Share on other sites

Hi Diaco! Thanks for the quick response!

 

I tried this:

TweenLite.to($("#content li")[i], 1, {top:"150%", onCompleteScope:this.target, onComplete:function(){
                console.log(this); //appears to be TweenLite object
            }});

It seems like this gives me the same result as leaving off the onCompleteParams and onCompleteScope parameters all together. 

Link to comment
Share on other sites

I've just realized that it works when I use this.target in my actual callback, which must be what you meant.

Thank you!

Link to comment
Share on other sites

Hi,

 

What Diaco meant was this:

TweenLite.to($("#content li")[i], 1, {top:"150%", onComplete:function(){
  console.log(this.target);
}});
  • Like 6
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.
×