Skip to content

Bug: zoom.in(ratio) incorrectly uses last click on slider position instead of center #7959

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

Open
5 of 6 tasks
JakubBombik opened this issue Apr 16, 2025 · 0 comments
Open
5 of 6 tasks
Labels

Comments

@JakubBombik
Copy link

JakubBombik commented Apr 16, 2025

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/p/devbox/swiper-react-zoom-forked-2yr42c

Bug description

There's an inconsistency in the zoom behavior when using zoom.in() with different parameter types:

  1. When passing an Event object, zooming works correctly - it zooms in while maintaining focus on the cursor position (expected behavior)
  1. When passing a number (zoom ratio), the zoom centers on the last clicked position rather than the center of the slider (unexpected behavior)

Reproduction Steps:

  1. Initialize Swiper with zoom module
  2. Click anywhere on the slider
  3. Call twice swiper.zoom.in(ratio)
  4. Observe zoom centers on last clicked position instead of slider center

Expected Behavior

When providing a number parameter to zoom.in(), the zoom operation should:

  1. Default to the center of the slider container
  2. Maintain consistent behavior regardless of previous interactions
  3. Match the behavior seen in other zoom implementations where programmatic zoom typically centers

Actual Behavior

  • swiper.zoom.in(event) → Zooms to cursor position (correct)
  • swiper.zoom.in(ratio) → Zooms to last clicked position on slider (incorrect)

Swiper version

11.2.6

Platform/Target and Browser Versions

Chrome

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
Projects
None yet
Development

No branches or pull requests

1 participant