Jump to content
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!

Share this post


Link to post
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. 

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.