loryjs/lory

returnIndex returns 0 when slides count is not a multiple of slidesToScroll

Open

#611 建立於 2017年3月16日

在 GitHub 查看
 (10 留言) (3 反應) (3 負責人)JavaScript (2,284 star) (256 fork)batch import
bughelp wanted

描述

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.

貢獻者指南