API.getSlideIndex does not work correct with carousel
Code logic: var i = slide.API.opts()._carouselWrap.children(); var t = i.index(this); return(t%i.length());
i.length() in my case was 12, t was 4. Zero-based Index would be 0. but returned 4 (4%12)
fix: return(t%this.slideCount)
Edit: I used something similar to your demo "Carousel Pager"... there the API.getSlideIndex is also used.
Here is the correct code from carousel.js, line 9:
API.getSlideIndex = function( el ) { var slides = this.opts()._carouselWrap.children(); var i = slides.index( el ); return i % slides.length; };
instead of slides.length, use the slideCount, since there are more children in a wrapping carousel than actual slides.
@Laubeee can you be more specific in your code? do you mean to rewrite the last line to: return i % slideCount;
?
Im fixed it change condition in carousel.js, line 18 from: if ( opts.allowWrap === false && ( opts.currSlide + count ) > opts.slideCount - opts.carouselVisible ) to: if ( opts.allowWrap === false && ( opts.currSlide + count ) === opts.slideCount )
For carousel transition plugin for Cycle2; version: 20130528 This is slightly different from the above answers but along the same idea.
This is the change you need to make: line 9 onwards should read: API.getSlideIndex = function( el ) { var slides = this.opts()._carouselWrap.children(); var i = slides.index( el ); return i % opts.slideCount; };
line 16 onwards should read: API.next = function() { var count = opts.reverse ? -1 : 1; if ( opts.allowWrap === false && ( opts.currSlide + count ) > opts.slideCount - opts.carouselVisible ) return; opts.API.advanceSlide( count ); opts.API.trigger('cycle-next', [ opts ]).log('cycle-next'); };