Jump to content
Search Community

Access stagger element/index possible?

therddlr 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

Is this possible to access animated element node or at least some index of stagger in onComplete? I see no data in fucntion

 

this.tl.staggerFromTo('#hello > path', 2, {
  drawSVG: '50% 50%'
}, {
  drawSVG: '100%',
  onComplete: (i) => {
    console.log('DONE', i) // undefined
  }
}, 1)

 

For example, I want to add fill when stagger of particular element is complete. Or other stuff...

Link to comment
Share on other sites

You can get the element in the callback using this.target. Note that arrow functions aren't scoped, so you would need to use a regular function.

 

// BAD
onComplete: () => {
  console.log(this.target) 
}

// GOOD
onComplete: function() {
  console.log(this.target) 
}

 

 

See the Pen EGxZVx by osublake (@osublake) on CodePen

 

 

 

If you need the index, you can create the stagger in a loop. That's all GSAP is doing. 

 

See the Pen VqwPem by osublake (@osublake) on CodePen

 

 

  • Like 5
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...