Jump to content
Search Community

How to pass element to onComplete function?

dwillis 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

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

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...