@@ -29,6 +29,8 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
29
29
let fakeGestureMoved ;
30
30
const evCache = [ ] ;
31
31
const gesture = {
32
+ originX : 0 ,
33
+ originY : 0 ,
32
34
slideEl : undefined ,
33
35
slideWidth : undefined ,
34
36
slideHeight : undefined ,
@@ -158,7 +160,8 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
158
160
}
159
161
if ( gesture . imageEl ) {
160
162
const [ originX , originY ] = getScaleOrigin ( ) ;
161
- gesture . imageEl . style . transformOrigin = `${ originX } px ${ originY } px` ;
163
+ gesture . originX = originX ;
164
+ gesture . originY = originY ;
162
165
gesture . imageEl . style . transitionDuration = '0ms' ;
163
166
}
164
167
isScaling = true ;
@@ -187,7 +190,6 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
187
190
if ( zoom . scale < params . minRatio ) {
188
191
zoom . scale = params . minRatio + 1 - ( params . minRatio - zoom . scale + 1 ) ** 0.5 ;
189
192
}
190
-
191
193
gesture . imageEl . style . transform = `translate3d(0,0,0) scale(${ zoom . scale } )` ;
192
194
}
193
195
function onGestureEnd ( e ) {
@@ -216,18 +218,22 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
216
218
gesture . slideEl . classList . add ( `${ params . zoomedSlideClass } ` ) ;
217
219
} else if ( zoom . scale <= 1 && gesture . slideEl ) {
218
220
gesture . slideEl . classList . remove ( `${ params . zoomedSlideClass } ` ) ;
219
- gesture . imageEl . style . transformOrigin = `` ;
220
221
}
221
- if ( zoom . scale === 1 ) gesture . slideEl = undefined ;
222
+ if ( zoom . scale === 1 ) {
223
+ gesture . originX = 0 ;
224
+ gesture . originY = 0 ;
225
+ gesture . slideEl = undefined ;
226
+ }
222
227
}
223
228
function onTouchStart ( e ) {
224
229
const device = swiper . device ;
225
230
if ( ! gesture . imageEl ) return ;
226
231
if ( image . isTouched ) return ;
227
232
if ( device . android && e . cancelable ) e . preventDefault ( ) ;
228
233
image . isTouched = true ;
229
- image . touchesStart . x = e . pageX ;
230
- image . touchesStart . y = e . pageY ;
234
+ const event = evCache . length > 0 ? evCache [ 0 ] : e ;
235
+ image . touchesStart . x = event . pageX ;
236
+ image . touchesStart . y = event . pageY ;
231
237
}
232
238
function onTouchMove ( e ) {
233
239
if ( ! eventWithinSlide ( e ) || ! eventWithinZoomContainer ( e ) ) return ;
@@ -293,8 +299,20 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
293
299
e . stopPropagation ( ) ;
294
300
295
301
image . isMoved = true ;
296
- image . currentX = image . touchesCurrent . x - image . touchesStart . x + image . startX ;
297
- image . currentY = image . touchesCurrent . y - image . touchesStart . y + image . startY ;
302
+ const scaleRatio =
303
+ ( zoom . scale - currentScale ) / ( gesture . maxRatio - swiper . params . zoom . minRatio ) ;
304
+ const { originX, originY } = gesture ;
305
+
306
+ image . currentX =
307
+ image . touchesCurrent . x -
308
+ image . touchesStart . x +
309
+ image . startX +
310
+ scaleRatio * ( image . width - originX * 2 ) ;
311
+ image . currentY =
312
+ image . touchesCurrent . y -
313
+ image . touchesStart . y +
314
+ image . startY +
315
+ scaleRatio * ( image . height - originY * 2 ) ;
298
316
299
317
if ( image . currentX < image . minX ) {
300
318
image . currentX = image . minX + 1 - ( image . minX - image . currentX + 1 ) ** 0.8 ;
@@ -381,6 +399,8 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
381
399
gesture . slideEl = undefined ;
382
400
gesture . imageEl = undefined ;
383
401
gesture . imageWrapEl = undefined ;
402
+ gesture . originX = 0 ;
403
+ gesture . originY = 0 ;
384
404
}
385
405
}
386
406
@@ -498,7 +518,8 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
498
518
translateY = 0 ;
499
519
}
500
520
if ( forceZoomRatio && zoom . scale === 1 ) {
501
- gesture . imageEl . style . transformOrigin = `` ;
521
+ gesture . originX = 0 ;
522
+ gesture . originY = 0 ;
502
523
}
503
524
gesture . imageWrapEl . style . transitionDuration = '300ms' ;
504
525
gesture . imageWrapEl . style . transform = `translate3d(${ translateX } px, ${ translateY } px,0)` ;
@@ -537,10 +558,11 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
537
558
gesture . imageWrapEl . style . transform = 'translate3d(0,0,0)' ;
538
559
gesture . imageEl . style . transitionDuration = '300ms' ;
539
560
gesture . imageEl . style . transform = 'translate3d(0,0,0) scale(1)' ;
540
- gesture . imageEl . style . transformOrigin = `` ;
541
561
542
562
gesture . slideEl . classList . remove ( `${ params . zoomedSlideClass } ` ) ;
543
563
gesture . slideEl = undefined ;
564
+ gesture . originX = 0 ;
565
+ gesture . originY = 0 ;
544
566
}
545
567
546
568
// Toggle Zoom
0 commit comments