Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiper Pagination Dynamic Bullets work incorrectly when loop is enabled #6587

Closed
5 of 6 tasks
electrodrel opened this issue Apr 14, 2023 · 0 comments
Closed
5 of 6 tasks

Comments

@electrodrel
Copy link

Check that this is really a bug

  • I confirm

Reproduction link

https://codepen.io/electrodrel/pen/VwEaKGE

Bug description

Pagination bullets are shifting to the left when looped if dynamicBullets option is enabled. It happens even if the number of slides are smaller than the value of dynamicMainBullets parameter (see the demo). The shifted dots on the left are 'converted' to the dynamic (smaller dots) making the whole pagination look off.

From my quick investigation, something is incorrect in the offset calculation once the slides are looped over and thus rearranged. Here is the place where I suspect something is off:

if (params.dynamicBullets) {
const dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4);
const bulletsOffset =
(bulletSize * dynamicBulletsLength - bulletSize) / 2 - midIndex * bulletSize;
const offsetProp = rtl ? 'right' : 'left';
bullets.forEach((bullet) => {
bullet.style[swiper.isHorizontal() ? offsetProp : 'top'] = `${bulletsOffset}px`;
});
}

Possibly, the midIndex is incorrectly calculated in the loop mode.

Expected Behavior

When looped over the pagination bullets they should not shift to any side and stay centred, just like when dynamicBullets is off:

Screen.Recording.2023-04-14.at.4.39.32.PM.mov

Actual Behavior

After the first loop is done, the dots shift to the left side, and the shifted dots are rendered as the 'dynamic' ones even though the number of slides is less than the dynamicMainPoints

Screen.Recording.2023-04-14.at.4.41.48.PM.mov

Swiper version

9

Platform/Target and Browser Versions

macOS, Chrome, Firefox

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant