Jump to content
GreenSock

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

TweenMax global 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

Hi, i have a problem, i need to know if any element on the page start/end tweening with TweenMax. Can i add something like global callback, that will fire on every tween start/end.
P.S. sorry for my bad english.

Link to comment
Share on other sites

No, not easily. Keep in mind that the engine creates tweens via tons of methods: to(), from(), fromTo(), staggerFrom(), staggerFromTo(), so this type of change would have to happen somewhere in the core. It is possible that you could extend the base Animation class or TweenLite and try to add that functionality.

 

If you need a simpler and less flexible implementation you could create your own helper function that gives your to() tweens an onComplete or onStart like:

 

to(".green", 1, {opacity:0})
to(".orange", 1, {opacity:0, delay:1})
to(".grey", 1, {opacity:0, delay:2})




function to(target, duration, vars){
  var t =TweenMax.to(target, duration, vars);
  t.eventCallback("onComplete", logIt)
}


function logIt() {
  console.log("a tween has finished", this.target[0]);
}

 

http://codepen.io/GreenSock/pen/dXLRpG?editors=0001

  • Like 1
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.
×