v0wels
v0wels

Reputation: 55

Linking slideshows using Cycle2

I'm looking for a way to link slideshows together using Cycle2. I know there was a way to do this in the original Cycle, but the new API is quite a bit different.

Basically, I'll need 2 separate areas for different slideshows, but I need them linked so that if I were to click Next on one slideshow, the other would advance as well. This also goes for pagers; when I try using data-cycle-pager="#pager" on both slideshows, the pager gets duplicated, and things start breaking.

Any luck on this is much appreciated. Thanks!

Upvotes: 1

Views: 918

Answers (1)

lucuma
lucuma

Reputation: 18339

I would do the following:

  1. Add the next/prev to one of the slideshows
  2. Hook into that slideshow's after event and manually change the other slider.

Here is the code: http://jsfiddle.net/lucuma/tQ4Jj/4/

HTML:

<div id="slideone" class="cycle-slideshow item" data-cycle-timeout="3000" data-cycle-speed="300" data-cycle-slides="> div.cycle-slide" data-cycle-fx="fade" data-cycle-pager-template="<a href='#'>{{cycleTitle}}</a>">

    <div class="cycle-slide"  data-cycle-title="Title 1" >
        <img src="http://placehold.it/550x550/" />
        <h2>My title 1</h2>
    </div>
    <div class="cycle-slide">
        <img src="http://placehold.it/550x550/ff0000" data-cycle-title="Title 2" /> 
<h2>My title 2</h2>
    </div>
    <div class="cycle-slide" data-cycle-title="Title 3">
        <img src="http://placehold.it/550x550/" />
<h2>My title 3</h2>
    </div>

     <a class="cycle-prev">Prev</a>&nbsp;&nbsp;<a class="cycle-next">Next</a>
</div>

<br /><br /><br /><br /><br />
<div id="slidetwo"  class="cycle-slideshow item" data-cycle-timeout="3000" data-cycle-speed="300" data-cycle-slides="> div.cycle-slide" data-cycle-fx="fade" data-cycle-paused="true">

    <div class="cycle-slide"  data-cycle-title="Title 1" >
        <img src="http://placehold.it/550x550/" />
        <h2>My title 1</h2>
    </div>
    <div class="cycle-slide">
        <img src="http://placehold.it/550x550/ff0000" data-cycle-title="Title 2" /> 
<h2>My title 2</h2>
    </div>
    <div class="cycle-slide" data-cycle-title="Title 3">
        <img src="http://placehold.it/550x550/" />
<h2>My title 3</h2>
    </div>


</div>

JS:

$( '#slideone' ).on( 'cycle-next', function( event, opts ) {
   $('#slidetwo').cycle('next'); 
});

$( '#slideone' ).on( 'cycle-prev', function( event, opts ) {
    $('#slidetwo').cycle('prev');
});

Upvotes: 1

Related Questions