Jump to content
Search Community

Uncaught Cannot tween a null target.

_Greg _ 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

Hi!

Can someone help me, i can't find error.

I want to create simple animation with hide/show some div's using jQuery and GSAP

Everything work well but in console i have error: Uncaught Cannot tween a null target.

 

 

$(document).ready(function ($) {
    if($('#teamBio').length){
        var bioText = $('.bioText'),
            teamBtns = $('.btns'),
            longBio = bioText.find('.longBio'),
            certBio = bioText.find('.certBio'),
            shortBio = bioText.find('.shortBio');
        
        teamBtns.each(function(i){
            var tl_blocks = new TimelineMax({paused:true});

            tl_blocks
                    .fromTo(teamBtns[i], 0.3,  {width:"40%", autoAlpha:1}, { width: "0%", autoAlpha:0})
                    .fromTo(bioText[i], 0.3, {width:"60%"}, { width:'100%'}, "-=0.3")
                    .to(shortBio[i], 0.3, {autoAlpha:0, display:"none"})
                    .to([longBio[i], certBio[i]], 0.3, {display:"block", autoAlpha:1});

            $(this).click(function(){
               tl_blocks.play();
                return false;
            })
        });
    }
});

 

Link to comment
Share on other sites

It's pretty tough to diagnose for sure without a demo (like a codepen), but my guess is that you have a different number of buttons/bios/shortbios/longbios/certbios. 

 

You're looping through the "teamBtns", but then you're using the same index value to look up other items like bioText but if teamBtns has 10 elements and bioText only has 9, then you're gonna be getting a null value when you try bioText[9] (the 10th element). Trying to tween a null value ain't gonna work :)

 

If you still need help, please post a reduced test case as a codepen and we'd be happy to take a peek. 

 

Enjoy GSAP! 

  • Like 3
Link to comment
Share on other sites

18 minutes ago, GreenSock said:

You're looping through the "teamBtns", but then you're using the same index value to look up other items like bioText but if teamBtns has 10 elements and bioText only has 9, then you're gonna be getting a null value when you try bioText[9] (the 10th element). Trying to tween a null value ain't gonna work :)

 

 

 

Ohhh.. yes, you're right, I did not pay attention 

Thank you, Jack.

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