@@ -494,6 +494,8 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
494
494
mousePanStart . y = e . clientY ;
495
495
image . startX = newX ;
496
496
image . startY = newY ;
497
+ image . currentX = newX ;
498
+ image . currentY = newY ;
497
499
}
498
500
499
501
function zoomIn ( e ) {
@@ -560,6 +562,8 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
560
562
touchY = image . touchesStart . y ;
561
563
}
562
564
565
+ const prevScale = currentScale ;
566
+
563
567
const forceZoomRatio = typeof e === 'number' ? e : null ;
564
568
if ( currentScale === 1 && forceZoomRatio ) {
565
569
touchX = undefined ;
@@ -590,8 +594,18 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
590
594
translateMaxX = - translateMinX ;
591
595
translateMaxY = - translateMinY ;
592
596
593
- translateX = diffX * zoom . scale ;
594
- translateY = diffY * zoom . scale ;
597
+ if (
598
+ prevScale > 0 &&
599
+ forceZoomRatio &&
600
+ typeof image . currentX === 'number' &&
601
+ typeof image . currentY === 'number'
602
+ ) {
603
+ translateX = ( image . currentX * zoom . scale ) / prevScale ;
604
+ translateY = ( image . currentY * zoom . scale ) / prevScale ;
605
+ } else {
606
+ translateX = diffX * zoom . scale ;
607
+ translateY = diffY * zoom . scale ;
608
+ }
595
609
596
610
if ( translateX < translateMinX ) {
597
611
translateX = translateMinX ;
@@ -614,6 +628,9 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
614
628
gesture . originX = 0 ;
615
629
gesture . originY = 0 ;
616
630
}
631
+
632
+ image . currentX = translateX ;
633
+ image . currentY = translateY ;
617
634
gesture . imageWrapEl . style . transitionDuration = '300ms' ;
618
635
gesture . imageWrapEl . style . transform = `translate3d(${ translateX } px, ${ translateY } px,0)` ;
619
636
gesture . imageEl . style . transitionDuration = '300ms' ;
@@ -647,6 +664,8 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
647
664
}
648
665
zoom . scale = 1 ;
649
666
currentScale = 1 ;
667
+ image . currentX = undefined ;
668
+ image . currentY = undefined ;
650
669
image . touchesStart . x = undefined ;
651
670
image . touchesStart . y = undefined ;
652
671
gesture . imageWrapEl . style . transitionDuration = '300ms' ;
0 commit comments