joe223 / tiny-swiper

Ingenious JavaScript Carousel powered by wonderful plugins. Lightweight yet extensible. Import plugins as needed, No more, no less.
https://tiny-swiper.js.org
1.29k stars 58 forks source link

Navigation does not honor loop mode when using only two slides #66

Open bediu opened 3 years ago

bediu commented 3 years ago

Describe the bug Navigation does not honor loop mode when using only two slides, it keeps going back and forth.

Expected behavior\ Navigation should honor loop mode when using only two slides, and change the slides according to the navigation element clicked [prev, next]

Information

Tiny-Swiper demo - Plugin - Mousewheel

bediu commented 3 years ago

Note, for anyone that wants a bad temporary hack, add two extra slides that are the same. One issue was that with this solution I had to implement my own navigation plugin using the after-slide event because four bullet points would show instead of two.

joe223 commented 3 years ago

@bediu Would you like to create a fix PR😄?

bediu commented 3 years ago

@bediu Would you like to create a fix PR?

I can try to fix this but I'm not familiar with the codebase. Can you share some information where do I start?

joe223 commented 3 years ago

@bediu Sorry, I'm kinda busy this days so can not reply to you soon.

I thought the problem is caused by getOffsetSteps. This function does not return the right value on line 207, thus swiper can not set initial offset for rebounding animation before sliders move.

https://github.com/joe223/tiny-swiper/blob/a7a95e6db5c5735b0e50d87dcdd7fdedfcfb004d/packages/tiny-swiper/src/core/state/operations.ts#L186-L222