Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RSeidelsohn opened this issue Mar 16, 2017 · 10 comments

Comments

@RSeidelsohn
Copy link

RSeidelsohn commented Mar 16, 2017

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.

@dimaip
Copy link

dimaip commented Apr 21, 2017

This is a major bummer for me, I need to hide prev and next links when they are inactive, and I don't know how to do it if I can't rely on correct index.
For now I have to keep track of index manually: https://github.com/psmb/PsmbDistr/blob/master/Packages/Sites/Sfi.Site/Frontend/js/init.lory.js#L49

@nstanard
Copy link
Collaborator

@RSeidelsohn First, thank you for providing so much detail, a link, and opening a PR. I'll take a look at this tonight.

@richardtoner
Copy link

What is the status of this bug?

We've identified the returnIndex error in a number of our use cases, so just want to check whether this is something we should look to fix on our side or wait for a fix?

@Saturate
Copy link
Collaborator

Hey @richardtoner feel free to create a PR, as this seem to have been stalled!

@cmoeser
Copy link

cmoeser commented May 24, 2018

Experiencing this issue as well. 'active' class never gets added to last slide.

@RSeidelsohn
Copy link
Author

RSeidelsohn commented May 24, 2018

@cmoeser : You might want to give my fork lory-lesara a try. It solves the issue for me.

@cmoeser
Copy link

cmoeser commented May 25, 2018

@RSeidelsohn Awesome! Thanks so much!

@ibrokemycomputer
Copy link

ibrokemycomputer commented Jun 29, 2018

@RSeidelsohn Thank you so much for that. We are on a time crunch and you saved the day.

@meandmax I have to mention, you tagged this as "help wanted" and the help was provided. Does the fork conflict with this repo or is it something you can pull in?

The bandwidth cost of importing lory vs other sliders (swiper, slick - to name a couple) makes it extremely attractive to RAIL/network performance-oriented developers. It would be nice to consider your library stable and active so our agency can confidently use it in production environments. If you still are actively seeking help please let me know, I would be glad to look into some of the issues.

@meandmax
Copy link
Collaborator

@ibrokemycomputer I would really appreciate it if you want to help/contribute. The reason I did not fix this issue yet is, that for now I do not have a way to make this work for all cases.

Also to me it is not even clear what should lory return in the case mentioned above (12 or 14)? When you have 4 slides visible which index is the currentIndex?

Cheers,
Max

@RSeidelsohn
Copy link
Author

@meandmax Well, it should return 14. And for this I created the fork of lory, named lory-lesara (I work for a company named Lesara where we use this fork). I add this functionality as a feature, so in order to enable it, you have to pass an additional parameter. If you don't, the code behaves exactly as the original lory does. It is just an additional feature for users that have varying numbers of slides (i.e. not always exact multiples of the visible slides) and want the arrows to disappear when the last slide has been reached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants