returnIndex returns 0 when slides count is not a multiple of slidesToScroll
#611 opened on Mar 16, 2017
Description
This special use case is currently bugging me - I have varying numbers of slides and I want to hide the next/prev slider buttons when the slides are at the beginning or the end of the list. But when the total number of slide elements is less than 2 * slidesToScroll (the number of slides that are visible at once in my case (4 in the example)), then returnIndex() returns 0. If there are more than 2 * slidesToScroll but still not an exact multiple of slidesToScroll, then at the end of the scrolling - i.e. when the last slide is reached - returnIndex() returns the previous index. For example when I have 4 slides visible and slidesToScroll equals 4, and I have 14 slides, then when the last slide is reached, returnIndex() returns 12 instead of 14.
I've prepared a codepen for this: http://codepen.io/rseidelsohn/pen/OpxGjr
This special issue could be resolved by changing
/**
* update the index with the nextIndex only if
* the offset of the nextIndex is in the range of the maxOffset
*/
if (slides[nextIndex].offsetLeft <= maxOffset) {
index = nextIndex;
}
to
/**
* update the index with the nextIndex always
*/
index = nextIndex;
but I haven't figured out under which condition this will break the slider functionality - so far in our project it works all fine.