darsain / sly

JavaScript library for one-directional scrolling with item based navigation support.
http://darsa.in/sly
2.87k stars 497 forks source link

activateMiddle index and hidden items #207

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hello,

I use Sly with forcecentered itemNav and use activateMiddle and activeOn (click). It works fine but if I hide some elements (I know it's not recommanded), then the index of the active element (on the middle) is wrong. How can I modify this behaviour. Is there a way to only search prev/next index for item that don't have a certain css class?

I just need to know where I can find the code that retrieve the acitveMiddle index. I try with getIndex() but without success (because I can't know if the slider was slide left or right)...

Thank you.

lolo

darsain commented 9 years ago

You have to specify itemSelector option, and call .reload() when something changes.

ghost commented 9 years ago

Yes but If I hide some item even with the selector (add :not() css property) it will not match the right active item after reload. There is a problem for sure. The active item after reload doesn't work if the element was hidden before to reload.

Is there a way to refind the current item in the middle?

https://jsfiddle.net/kn3gq695/7/

darsain commented 9 years ago

Yeah, Sly can't account for that. I would have to implement a diffing engine...

The answer is don't hide, but use add & remove methods.

ghost commented 9 years ago

But your selector option finally do not do what is intended for. Reload doesn't take into account selector option. Maybe can you just point me where I can find the function to modify or just how can I just find the new centered item.

https://jsfiddle.net/kn3gq695/7/

darsain commented 9 years ago

The whole Sly API is documented in docs folder. I won't tell you anything new.

Selector option was hacked in when one of the guys requested it. It works, but there are issues.

The preferred way how to manage elements is via add & remove methods. Both documented in the link above.