Jump to content
Search Community

Animating each child element

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

I'm new to GSAP and really like it so far. I have one challenge that I think could be easily solved by SplitText, but unfortunately my company isn't interested in going the membership route. Is there an alternative to achieving the same thing?

 

I have a parent element with a header and a variable amount of paragraphs. I'd like to animate the header, then each paragraph in turn. That is, once the first paragraph is finished animating, the second paragraph starts animating. When the 2nd paragraph is finished, the 3rd starts animating, and so on.

 

Here is some sample HTML:

<article>
   <h1>My header</h1>
   <p>First paragraph</p>
   <p>Second paragraph</p>
</article>

Does GSAP have an equivalent of jQuery's $.each() function, such that I could call the same animation on an element with a class, like:

$( 'article p' ).each( function() {
   tl.from( $( this ), 1.5, { rotationX : -90, transformOrigin : 'left top', ease : Elastic.easeInOut } );
} )

That's just pseudo code to convey my idea. I realize it won't work ;)

 

Thanks in advance for any help!

Link to comment
Share on other sites

Hi and welcome to the forums.

 

Michael71 a respected community member, created some time ago a JQuery text plugin, but I haven't used it, so I don't know if it'll fit your needs, but is worth to take a look at it.

 

Here's Michael's blog post:

http://nightlycoding.com/index.php/2013/03/text-animation-jquery-plugin-released/

 

And this is the code repository in github:

http://netgfx.github.io/SplitText/

 

AS for the engine having a function or method to handle and sequence arrays you can try with the stagger methods:

http://api.greensock.com/js/com/greensock/TweenMax.html#staggerFrom()

 

See which one is the best for you in this case.

 

Also the code you posted should work, as far as I can see. You're adding the tweens to a timeline through an each loop, that will add the tween in sequence and since you're not using any positioning indication each tween should be added at the end of the timeline, so the first element should be animated and the the second, third and so on.

 

Take a look at Carl's video tutorial to work with timelines and sequences is a great learning resource:

http://www.greensock.com/sequence-video/

 

I've created a codepen so you can see it in action:

See the Pen xbapq by rhernando (@rhernando) on CodePen

 

Hope this helps,

Cheers,

Rodrigo.

  • Like 1
Link to comment
Share on other sites

Thank you both for your detailed and thoughtful answers. I appreciate you taking the time to create working examples!

 

Bassta, your Fiddle was exactly what I needed.

 

Rodrigo, your Codepen introduced me to AutoAlpha, which prevented me from asking a follow up -- how do I hide the animations until they are ready?

 

Things are working great now, thanks!

Link to comment
Share on other sites

  • 2 years later...

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