Jump to content
Search Community

Call function in timeline

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

Im new here. Can you help me? Im would like to call function in this way. Is it possible? How?

.to('.col-box:nth-child(3)', 1, {opacity: 1,delay: 0.2}, 0)
//a call function
.to('.col-box:nth-child(4)', 1, {opacity: 1,delay: 0.3}, 0)	
.to('.col-box:nth-child(5)', 1, {opacity: 1,delay: 0.4}, 0)	

Thanx

  • Like 1
Link to comment
Share on other sites

You can use the .add() method to place a function in the timeline where ever you like.

.to('.col-box:nth-child(3)', 1, {opacity: 1,delay: 0.2}, 0)
.add( function(){ console.log('Woohoo!') } )
.to('.col-box:nth-child(4)', 1, {opacity: 1,delay: 0.3}, 0)	
.to('.col-box:nth-child(5)', 1, {opacity: 1,delay: 0.4}, 0)

See the Pen vgxjQb?editors=1111 by sgorneau (@sgorneau) on CodePen

  • Like 7
Link to comment
Share on other sites

  • 3 years later...
On 1/20/2017 at 7:55 PM, Carl said:

You can also use call() if you need to pass in parameters to the function you are calling.


tl.call(myFunction, ["param1", "param2"]);

Check out the docs. Lots of good info: https://greensock.com/docs/#/HTML5/All/TimelineLite/call/

Is there way to add delay before call? Am looping through an array to call a function via timeline  and playing it after loop ends.

 

Tried delay parameter but not working;

 outlines.forEach(element => {
        tl.delay(1).call(animatePath, [canvaselement0.01], duration)
        duration = duration + 0.2
    });
Link to comment
Share on other sites

@anishjana_ It's not clear to me from your brief description exactly what you want to do. You can use the third (position) parameter of .call() to place the function call where you need it to be within the timeline as the docs cover. Currently you have duration in that slot. Perhaps it'd help you to better understand the position parameter.

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