cycle2 icon indicating copy to clipboard operation
cycle2 copied to clipboard

API.getSlideIndex does not work correct with carousel

Open Laubeee opened this issue 12 years ago • 4 comments

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.

Laubeee avatar Jul 11 '13 13:07 Laubeee

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 avatar Jul 16 '13 14:07 Laubeee

@Laubeee can you be more specific in your code? do you mean to rewrite the last line to: return i % slideCount;

?

wlanni avatar Apr 23 '14 08:04 wlanni

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 )

ghost avatar Oct 18 '15 10:10 ghost

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'); };

GemmaCowton avatar Jan 05 '17 10:01 GemmaCowton