Jump to content
Search Community

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

Posted

Hi,

 

my onComplete doesn't appear to be firing, please can someone advise why.

TweenLite.fromTo(obj,1, {height:minHeight+curHeight},{height:minHeight, onCompleteParams:[obj], onComplete:function(obj){obj.toggleClass('active')}});

Thanks

1DMF

jamiejefferson
Posted

No idea; that looks fine to me. It would help if you made a demo showing this issue in codepen or jsfiddle so we could investigate.

Posted

Well I replaced the anonymous function with a real one and it's working?

 

Though the params don't seem to work, so I've done it like this...

TweenLite.fromTo(obj, 1, {height:minHeight+curHeight}, {height:minHeight, onComplete:toggle(obj)});

Regards,

1DMF

Posted (edited)

However, I have just found that the onComplete is firing instantly and not on completion of animation?

 

What am I doing wrong?

 

UPDATE:

 

OK, so if you use parentheses and try to pass in arguments or void, the function fires immediately, so I went back to onCompleteParams and found that they must follow the onComplete special property.

 

In my original example I had the onCompleteParams before the onComplete, which appears not to work.

 

This is now working as desired...

TweenLite.fromTo(obj, 1, {height:minHeight+curHeight}, {height:minHeight, onComplete:toggle, onCompleteParams:[obj]});
Edited by 1DMF
jamiejefferson
Posted

Ah cool thanks for replying with your results. I'd never tried ordering them that way before and just assumed it would work

 

...which it does.......

Posted

No problem, I absolutely love GSAP and hope it helps others.

Posted

Hmmm.. that is weird .. I just made an example of the placement of onComplete after the onCompleteParams .. in a fromTo() and the onComplete fires as expected:

 

See the Pen xtkej by jonathan (@jonathan) on CodePen.

 

Do you see it too?

jamiejefferson
Posted

Yea totally working for me too. It's even working when I copy the exact tween (with valid height values) into your pen

 

See the Pen lnItb by anon (@anon) on CodePen.

 

Back to square one - we have no idea why that didn't work for you...

  • Like 1
Posted

yep,  your pen works for me too Jamie :blink:

Posted

? who knows.. all working now, so all good :-)

Posted

The order shouldn't matter at all. 

 

I bet there was something else going on in your code previously that caused things not to work, but I'm glad to hear it's working for you now. If you can show us a way to reproduce the faulty behavior, please do. Otherwise, good luck with the project. Happy tweening.

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