swiper icon indicating copy to clipboard operation
swiper copied to clipboard

Swiper jumps to last slide when adding slides dynamically in observer mode

Open Givized opened this issue 2 years ago • 0 comments

Check that this is really a bug

  • [X] I confirm

Reproduction link

https://codesandbox.io/s/swiper-slides-per-view-forked-zmly8r?file=/index.html

Bug description

Setup: Multiple slides per view Adding new slides, when end is reached Adding slides dynamically, using observer mode

Issue When new items are added, swiper jumps to last added slide, and doesn't maintain current position (active slide index).

So, in the example there are initially 5 slides. When we scroll to last slide (that is when slides 3-4-5 are displayed), 5 new slides are "loaded" and added to the end. When they are appended, Swiper immediately jumps to last slides (8-9-10), not maintaining it's current position, while it is expected that it stays on slides 3-4-5.

Expected Behavior

When dynamically adding slides to the end, if Swiper is currently on last slide, active index shouldn't change and no horizontal "scrolling" should occur

Actual Behavior

When dynamically adding slides to the end, if Swiper is currently on last slide, it jumps to the last slide that was just added

Swiper version

8.2.5

Platform/Target and Browser Versions

macOS Chrome 103.0.5060.114

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the docs.
  • [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • [X] 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

Givized avatar Jul 26 '22 07:07 Givized