nolimits4web / swiper

Most modern mobile touch slider with hardware accelerated transitions

Home Page:https://swiperjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

swiper.slideTo(5) Jumps to Penultimate Image Instead of Last Image

mircobalda opened this issue · comments

Check that this is really a bug

  • I confirm

Reproduction link

Go to this URL.

Bug description

I am experiencing an issue with the Swiper library when trying to programmatically slide to the last image in a swiper. Specifically, when I use the method swiper.slideTo(5) to slide to the last image in a set of 5 images, the swiper jumps to the penultimate image instead of the last one.

Expected Behavior

The swiper should slide to the 5th image (the last image).

Actual Behavior

The swiper slides to the 4th image (the penultimate image).

Swiper version

11.0.5

Platform/Target and Browser Versions

Windows, IIS, Chrome last version

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR

I faced smilar prolem to yours in my project. It seems there is totally broken logic:
If I try in yours example this:
slider.slideTo(0); it goes to slide nr. 4
slider.slideTo(1); it goes to slide nr. 0
slider.slideTo(2); it goes to slide nr. 1
slider.slideTo(3); it goes to slide nr. 2
slider.slideTo(4); it goes to slide nr. 3
again slider.slideTo(0); it goes to slide nr. 4 again

Note I haven't tested index 5, because slides are indexed from zero, so maximum index is 4.

It seems slide numbers are wrongly translated to internal slide numbers which are rotated by 1 for looping purposes.

Ah ok, I didnt get that by 0 I could jump to the last one, yes, a little bit messy but with this I will fix it.
Thank you very much!

Of course it is messy. It is a bug in swiperjs :) we can't use it as this. Because if your user for example swipe to the last slide by arrow buttons, then it is "working like a charm" (for a while):
4 -> 4
3 -> 3
2 -> 2
1 -> 1
0 -> 0

If it overflows to first slide by looping (using arrow buttons), we will get to the initial behavior again.

It is indisputable bug which should be fixed.

@mircobalda I have found solution for your case:
swiper.slideToLoop(