Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Bams

TweenMax.staggerFrom onCompleteAll doesnt fire!

Recommended Posts

hi!

 

As the title says : my TweenMax.staggerFrom onCompleteAll doesnt fire!

var leftButtons = $(".btnLeft");
var rightButtons = $(".btnRight");

TweenMax.staggerFrom ( leftButtons, 1, { x:"-50", opacity:0 }, 0.5, "+=0", myCompleteAll );


function myCompleteAll()
{
    alert ( "completeAll!" );
   // TweenMax.staggerFrom ( rightButtons, 1, { x:"+50", opacity:0 }, 0.5 );
}

i've checked and read a few topics about it before posting but i can't find what i'm doing wrong..

 

you can have a look at my CodePen here

 

thanks a lot

:-)

See the Pen ojdGam by sebastienbams (@sebastienbams) on CodePen

Link to comment
Share on other sites

Hello Bams, and Welcome to the GreenSock Forums!

 

The reason it is not working is due to the extra parameter "+=0"

 

See the Pen wKjPMJ by jonathan (@jonathan) on CodePen

TweenMax.staggerFrom( targets:Array, duration:Number, vars:Object, stagger:Number, onCompleteAll:Function, onCompleteAllParams:Array, onCompleteAllScope:* )

Here are the Docs to staggerFrom()

// staggerFrom(target, duration, {vars}, staggerNumber, onCompleteAll) 
TweenMax.staggerFrom ( leftButtons, 1, { x:"-50", opacity:0 }, 0.5, myCompleteAll );

So i believe you were looking to achieve this effect in total:

 

See the Pen jbxayY by jonathan (@jonathan) on CodePen


 

Then in your staggerFrom() you would pass parameters to your onCompleteParams

// staggerFrom(target, duration, {vars}, staggerNumber, onCompleteAll, onCompleteParams)
TweenMax.staggerFrom ( leftButtons, 1, { x:"-50", opacity:0 }, 0.5, myCompleteAll, [rightButton] );

Your complete code would look like this:

var svgElements = $(".svgElement");
var leftButtons = $(".btnLeft");
var rightButtons = $(".btnRight");

TweenMax.staggerFrom(leftButtons, 1, {x:"-50", autoAlpha:0}, 0.5, myCompleteAll,[rightButtons]);

function myCompleteAll(rb) { /* rb is the rightButtons var you pass as the parameter to myCompleteAll function */
  //alert ( "completeAll!" );
  TweenMax.staggerFrom(rb, 1, {x: "+50", autoAlpha: 0}, 0.5);
}

I think what you want to do is add this to your CSS as well

.btnLeft, .btnRight{
      visibility:hidden; /* sets initial hidden state of .btnLeft and .btnRight */
}

Using autoAlpha is better on performance and allows you to set the visibility to hidden when the elements opacity reaches 0

 

autoAlpha is part of the CSSPlugin:

 

http://greensock.com/docs/#/HTML5/GSAP/Plugins/CSSPlugin/

 

autoAlpha

  • Identical to opacity except that when the value hits 0 the visibility property will be set to "hidden" in order to improve browser rendering performance and prevent clicks/interactivity on the target. When the value is anything other than 0, visibility will be set to "inherit". It is not set to "visible" in order to honor inheritance (imagine the parent element is hidden - setting the child to visible explicitly would cause it to appear when that's probably not what was intended). And for convenience, if the element's visibility is initially set to "hidden" and opacity is 1, it will assume opacity should also start at 0. This makes it simple to start things out on your page as invisible (set your css visibility:hidden) and then fade them in whenever you want.
//fade out and set visibility:hidden
TweenLite.to(element, 2, {autoAlpha:0});
 
//in 2 seconds, fade back in with visibility:visible
TweenLite.to(element, 2, {autoAlpha:1, delay:2});

Resources:

staggerFrom() : http://greensock.com/docs/#/HTML5/GSAP/TweenMax/staggerFrom/

CSSPlugin autoAlpha : http://greensock.com/docs/#/HTML5/GSAP/Plugins/CSSPlugin/

 

Let us know if you need any more help :)

  • Like 5
Link to comment
Share on other sites

Thank you so much Jonathan!

I thought I had to pass "+=0" as a Position parameter before onCompleteAll (read that somewhere, but probably deprecated or something?)

 

It works like a charm now and I've learned AutoAlpha which will help me a lot too.

 

You guys rock, REALLY!

Cheers from France

  • Like 1
Link to comment
Share on other sites

Great job, Jonathan.

 

Bams, 

 

The extra parameter "+=0" is the position parameter that would be used when you are building a timeline. it tells the tweens where they need to be placed in the timeline.

 

TimelineLite and TimelineMax both have staggerFrom() methods that use the position parameter, whereas TweenMax.staggerFrom() does not.

  • Like 4
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.
×