Jump to content


How to set default values for callbacks?

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 find this: https://greensock.com/docs/#/HTML5/GSAP/TweenLite/vars/


and this is my code:

function tweenCompleteHandler() {

TweenLite.prototype.vars.onComplete = tweenCompleteHandler;

var animation = TweenLite.to("#box", 1, {
  x : 550

it didn't work? does TweenLite have something like jQuery.ajaxSetup() ?

See the Pen wBvNxP by anon (@anon) on CodePen

Link to comment
Share on other sites

Hi Cople :)


try this :

animation.vars.onComplete = tweenCompleteHandler;
  • Like 1
Link to comment
Share on other sites


Hi Cople  :)


try this :

animation.vars.onComplete = tweenCompleteHandler;


3Q. but what i want is set as global default value like defaultEase do, not on a instance.

Link to comment
Share on other sites

there's not any Global value for onComplete,onUpdate,...

at least that's what i know .

Link to comment
Share on other sites

I'm not sure why you thought altering the prototype would do that, but Diaco.AW is correct - there is no global default for setting an onComplete. It should be relatively easy for you to do that on your own, though, with a helper function. One idea:

function tween(target, duration, vars) {
    if (!vars.onComplete) {
        vars.onComplete = yourDefaultFunction;
    return TweenLite.to(target, duration, vars);
tween(element, 1, {x:100, y:200});

Another idea: 

function vars(values) {
    if (!values.onComplete) {
        values.onComplete = yourDefaultFunction;
    return values;
TweenLite.to(element, 1, vars({x:100, y:200}));

There are lots of ways you could do it.

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