Jump to content
GreenSock

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

Proper use of onComplete callback

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

Trying to test onStart and onComplete callbacks:

 

this code write 'play' and 'finish' in the console at the same time (immediately start time). What is wrong here? How can I fire a function when timeline ends?

 

Thanks!

 

function bannerDown(){
      let tl = new TimelineMax({
        onStart: console.log('play'),
        onComplete: console.log('finish'),
      });
      tl
        .to('.content', .5, {
          paddingTop: bannerHeight,
          ease: Power4.easeOut,
        }, 0)
        .to('.banner', .5, {
          y: 0,
          height: 'auto',
          ease: Power4.easeOut,
        }, 0);
        return tl;
    }
Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,

 

When you specify callbacks you should not include any () as that will tell those functions to execute immediately.

You just pass the name of the function like:

let tl = new TimelineMax({
        onStart: myOnStartFunction
      });



function myOnStartFunction(){

 // do stuff

}

 

In the case where you need to pass parameters, you do that separately as an array

console.clear();
var tl = new TimelineLite({onStart:console.log, onStartParams:["start"], onComplete:console.log, onCompleteParams:["complete"]})

tl.to("h1", 3, {x:200});

 

 

  • Like 2
Link to comment
Share on other sites

Yes! Thank you very much for the quick and accurate answer.

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