Jump to content
Search Community

Callback using .add is returning undefined

Forxs 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 have this function:

 

function changeInfo(element){
	new TimelineMax();
	tl = new TimelineMax();

	tl.to('.info-row .content', 0.3, {opacity: 0}, 0)
	  .add(insertContent(element))
	  .to('.info-row .content', 0.3, {opacity: 1}, 0.6)

	//insertContent(element);
}

 

Which is fading out some content, run a function to insert the new content, and then fade in the new content.

 

The browser is returning "Uncaught Cannot add undefined into the timeline; it is not a tween, timeline, function, or string."

 

If I comment out the timeline and just run insertContent(element); it works fine (all be it without the animation obviously). 

 

Any idea what I can do to fix this?

 

Cheers,

Link to comment
Share on other sites

So 'element' is just a jQuery DOM object. insertContent just pulls some information from that element and injects it into another element:

 

function insertContent(element){
	var infoContent = '<div class="image">';
	infoContent += element.find('.headshot_alternate').html();
	infoContent += '</div>';
	infoContent += '<div class="name">'+element.find('.info .name').html()+'</div>';
	infoContent += '<div class="position">'+element.find('.info .position').html()+'</div>';
	infoContent += '<div class="bio">'+element.find('.info .bio').html()+'</div>';

	$('.info-row .content').html('');
	$('.info-row .content').html(infoContent);
}

 

So the variable infoContent is just building the new content for the container. Then it injects it into '.info-row .content'.

Link to comment
Share on other sites

As @PointC said, you need to use .call(). 

 

Parentheses after a function will execute it immediately.

.add(insertContent(element))

 

Your function isn't returning anything, so that is essentially the same thing as this.

.add(undefined)

 

This will wait to call the function.

.call(insertContent, [element])

 

 

 

 

  • Like 6
Link to comment
Share on other sites

1 minute ago, OSUblake said:

As @PointC said, you need to use .call(). 

 

Parentheses after a function will execute it immediately.


.add(insertContent(element))

 

This will wait to call the function.


.call(insertContent, [element])

 

 

This sorted it, thank you!

  • 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.
×
×
  • Create New...