Skip to content

Swiper incorrectly calculates last slide as activeSlide on load. #7216

@learyjk

Description

@learyjk

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/s/swiper-bug-loop-centered-auto-width-kwj8ls?file=/index.html

Bug description

a slider with slidesPerView set to 'auto' in loop mode and centeredSlides set to true calculates the last slide as the active slide on load. In the demo you'll see that the first slide shown is slide 7, not slide 1.

  • changing the slide width in CSS from 20% to 21% causes the first slide to show.

  • can also play with initialSlide value to correct it.

My guess is some sort of math error when calculating the first slide when combo of slidesPerView 'auto', centeredSlides true, and loop mode are all in play.

Expected Behavior

  • I expect Slide 1 to be the first to show in the provided example.
  • I expect changing slide width in CSS to not change which slide is calculated to be first (i.e. I expect when initalSlide is set to 0, the first slide is shown.)

Actual Behavior

The last slide in the html is calculated to be the active slide on load.

Swiper version

11.0.5

Platform/Target and Browser Versions

Chrome, Safari

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions