Jump to content
Search Community

How do I make a seamlessly cycling slideshow?

bobdobbs 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've been struggling with my first challenge: making a seamlessly cycling slideshow with timelinemax.

 

So far, no matter what I do, after the animation cycles for the first time, I get an empty pane until the first animation in the chain completes. I've tried a number of ways to prevent this, but to no avail.

 

 

This is what I have so far:

 

My viewpane is 960px wide. It is initially occupied by the first slide, while the other slides are outside the right edge of the pane. All slides have a starting z-index of 100.

var tl = new TimelineMax({repeat : -1}) ;
            tl.to( slides[1] , 2,
                   {
                       left : 0,
                       // after first animation, secretly move
                       // first slide into new starting position
                       // and make sure it slides over the previous slide
                       onComplete : function (){
                           target = slides.eq(0) ;
                           target.css("left", "960px") ;
                           target.css("z-index", "2000") ;
                       }
                   }
                 )
                .to( slides[2] , 2,
                     {
                         left    : 0
                     }
                   )
                .to( slides[0], 2,
                     {
                         left : 0,
                         onComplete : function() {
                             console.debug( "completed last anim" );
                             // give the first slide it's oringal z-index,
                             slides.eq(0).css("z-index", "100") ;
                         }
                     }
                   ) ;
Link to comment
Share on other sites

Hi,

 

I wold like to suggest you a simplier way to achieve this effect:

 

 

See the Pen LckBh by burnandbass (@burnandbass) on CodePen

 

I explained the code here: http://bassta.bg/2013/05/simple-fade-infade-out-slideshow-with-tweenlite/

 

In my way you can add as many elements as you want :)

 

Also, try to move not the "left", but "x" position. Here is a pen: 

See the Pen nktrz by burnandbass (@burnandbass) on CodePen

 

I get better performance on modern browsers. 

  • Like 1
Link to comment
Share on other sites

Hi,

 

I completely agree with bassta that the best approach for this stuff is use CSS selectors and a simple function. Too often users have try using parent timelines with nested timelines inside, labels and a lot of stuff to achieve a content slider. 

 

I remember once doing something like that for two different posts in the forums, this one uses timelines, labels and controls:

See the Pen Bgjzw by rhernando (@rhernando) on CodePen

 

And this one has Bassta's approach:

See the Pen ydfBb by rhernando (@rhernando) on CodePen

 

As you can see the latter is completely dynamic, just like bassta's so if you add more images/slides, there's no problem and with a little tinker you can achieve it to go backwards, pause and resume, meanwhile make the first one dynamic will mean a lot more code and ultimately more trouble to get it to work properly.

 

Just my two cents.

 

Hope this helps,

Rodrigo.

  • Like 2
Link to comment
Share on other sites

Here is one that I was testing with a GSAP timeline.. a couple of posts ago

 

See the Pen qxsfc by jonathan (@jonathan) on CodePen

 

note its not that dynamic just a quick concept with timeline and tweens... .but with help from Rodrigo, it can go in reverse now...

 

if you want and by modifying it, and passing parameters of the active slide to the animateSlide functions it can become more dynamic. And just use one animateSlide function.

 

but like Rodrigo and Bassta said.. sometimes its best to keep it simple and not mess with timelines.. and just use a simple function and CSS selectors..

 

just my one cent :)

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