Jump to content


Carousel with TweenLite and JS only, cannot tween a null target

Go to solution Solved by Diaco,

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 everyone !


Hope you are fine.


I come to you because I am trying to make a carousel with images fading in / out.

I decided to use opacity (maybe it's not the best way to do it) and JS. I succeed to do something with JQuery but the performance were a disaster. Made my browser (chrome) crash.


Then I decided to make it with javascript and tried to realise something as light as possible (hard task).


But, when I thought my algorithm was good I was in front of 2 problems :


1) I don't succeed to make it infinite (not too hard to do)

2) I have an error during a loop : Cannot tween a null target.


I put some console.log everywhere at every stage but impossible to localise the moment where I am sending a null object to TweenLite. Dafuq


So, as you will see in my (short) codepen, am I missing something ?



I deeply thank you in advance for the time spend on my request.

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

Link to comment
Share on other sites

The reason you developed a null object is that you allowed your counter (array index) to surpass the size of the the array.  So when you called TweenLite on slide[3], the object didn't exist.


Here's a version which uses the js modulus (%) operator, which useful for things that cycle.

See the Pen wKaEaP by pixeldroid (@pixeldroid) on CodePen

  • Like 2
Link to comment
Share on other sites

Wow awesome, thank you very much guys !


@pixeldroid, I thought that if I have i < obj.length it assumes that if obj is a size of 5, i stop at 4. My bad and thx for the elementary lesson haha


And thank you again Diaco for this codepen :)

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.