Skip to content

Commit

Permalink
feat(zoom): in method now accepts custom zoom ratio
Browse files Browse the repository at this point in the history
fixes #5527
  • Loading branch information
nolimits4web committed Jan 17, 2023
1 parent 4949163 commit d88df61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/modules/zoom/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,17 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
touchY = image.touchesStart.y;
}

zoom.scale = gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio;
currentScale = gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio;
if (e) {
const forceZoomRatio = typeof e === 'number' ? e : null;
if (currentScale === 1 && forceZoomRatio) {
touchX = undefined;
touchY = undefined;
}

zoom.scale =
forceZoomRatio || gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio;
currentScale =
forceZoomRatio || gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio;
if (e && !(currentScale === 1 && forceZoomRatio)) {
slideWidth = gesture.slideEl.offsetWidth;
slideHeight = gesture.slideEl.offsetHeight;
offsetX = elementOffset(gesture.slideEl).left + window.scrollX;
Expand Down
4 changes: 2 additions & 2 deletions src/types/modules/zoom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export interface ZoomMethods {
disable(): void;

/**
* Zoom in image of the currently active slide
* Zoom in image of the currently active slide. Optionally accepts custom zoom ratio
*/
in(): void;
in(ratio?: number): void;

/**
* Zoom out image of the currently active slide
Expand Down

0 comments on commit d88df61

Please sign in to comment.