malsup / cycle2

2nd gen cycling
899 stars 238 forks source link

allowWrap bug with carousel plugin #756

Open acha5066 opened 8 years ago

acha5066 commented 8 years ago

I think there is a bug with the carousel plugin (Although it could be that I have misconfigured it). Using allowWrap: false disables the prev and next navigation. However, setting 'allowWrap: true' creates 3 times as many slides as there are, which makes the getSlideIndex method return the wrong index.

Steps to reproduce.

  1. Clone an existing Slideshow with $('.slideshow).clone().
  2. Use options as below.

Version I'm using:

jQuery 1.9 Cycle2 '2.1.6'; Carousel Plugin: v20141007

      // Init Cycle2.
      if ($this.hasClass('clone')) {
        $(behavior.carouselSelector).cycle({
          slides: behavior.slideSelector,
          pauseOnHover: false,
          fit: 1,
          log: false,
          reverse: 0,
          width: '100%',
          speed: 1000,
          timeout: 4000,
          swipe: 'true',
          autoHeight: 'calc',
        });
      } else {
        var numSlides = parseInt(behavior.slideSelector.size());
        $(behavior.carouselSelector).cycle({
          slides: behavior.slideSelector,
          pauseOnHover: false,
          log: true,
          speed: 1000,
          timeout: 4000,
          swipe: 'true',
          prev: '> .cycle-prev',
          next: '> .cycle-next',
          carouselVisible: numSlides, // Calculated depending on how many images there are.
          fx: 'carousel',
          carouselFluid: true,
        });
      }

      // When previous or next is clicked, advance the other slideshow
      var slideshows = $('.field--name-field-gallery-image').on('cycle-next cycle-prev', function(e, opts) {
        // advance the other slideshow
        slideshows.not(this).cycle('goto', opts.currSlide);
      });

      // On click of a slide get the index.
      // Move both slides to that index
      $('.navigator .cycle-slide').click(function(){
         var index = $('.navigator').data('cycle.API').getSlideIndex(this);
         slideshows.cycle('goto', index);
      });