Jump to content
Search Community

Get id/class in callback-function

Thomas 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

I am trying to get the id/class from the animated div in the callback-function.

 

What information does the callback-event contain? Is is the tween or is it possible to get information about the animated object the tween is using (in my case a div)?

 

Thanks in advanced! :)

 

 

Link to comment
Share on other sites

hello.. welcome to the forums .. you would use something like this:

var $box = $('div'),
    other = "hello!",
    tl = new TimelineMax({
        paused:true,
        onCompleteParams: ["{self}", $box, other],
        onComplete: function(t,b,o){
              console.log(t); // self = timeline instance
              console.log(; // box element to do stuff with
              console.log(o); // outputs "hello!"

              var myID = b.attr('id'); // gets id of b, which is $box
        }
     });

tl.add( TweenMax.to($box, 3, {css:{autoAlpha:1}}, "mylabel" );
tl.play();

if you go to the docs and scroll down, and review the special properties.. there you will find callbacks, like onComplete, onStart, etc .. you would use onCompleteParams, onStartParams, etc ...
 

http://api.greensock.com/js/com/greensock/TimelineMax.html

 

you pass your variables through the onCompleteParams which will make those variables available within the callback function.

  • onComplete : Function - A function that should be called when the timeline has completed
  • onCompleteParams : Array - An Array of parameters to pass the onComplete function.

    For example, new TimelineMax({onComplete:myFunction, onCompleteParams:["param1", "param2"]}); To self-reference the timeline instance itself in one of the parameters, use "{self}", like: onCompleteParams:["{self}", "param2"]

passing a timeline instance to use the timeline.progress():

var $box = $('div');
    tl = new TimelineMax({paused:true});
tl.add ( TweenMax.to($box, 3, { 
                ease: Linear.easeNone,
		onUpdateParams: ["{self}",$box],
		onUpdate: function(t,{
			var wp = t.progress(); // gets the current timeline progress on each update
			TweenMax.set(b,{scale:wp});
		}							
}), "mylabel" );
tl.play();

hope this helps

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