Skip to content

Commit 6700980

Browse files
committed
fix(zoom): fix zoom stick on pointer out
fixes #6396
1 parent f998115 commit 6700980

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/modules/zoom/zoom.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
120120

121121
// Events
122122
function onGestureStart(e) {
123+
if (e.pointerType === 'mouse') {
124+
evCache.splice(0, evCache.length);
125+
}
123126
if (!eventWithinSlide(e)) return;
124127
const params = swiper.params.zoom;
125128
fakeGestureTouched = false;
@@ -189,11 +192,13 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
189192
}
190193
function onGestureEnd(e) {
191194
if (!eventWithinSlide(e)) return;
195+
if (e.pointerType === 'mouse' && e.type === 'pointerout') return;
192196

193197
const params = swiper.params.zoom;
194198
const zoom = swiper.zoom;
195199
const pointerIndex = evCache.findIndex((cachedEv) => cachedEv.pointerId === e.pointerId);
196200
if (pointerIndex >= 0) evCache.splice(pointerIndex, 1);
201+
197202
if (!fakeGestureTouched || !fakeGestureMoved) {
198203
return;
199204
}
@@ -555,7 +560,7 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
555560

556561
swiper.wrapperEl.addEventListener('pointerdown', onGestureStart, passiveListener);
557562
swiper.wrapperEl.addEventListener('pointermove', onGestureChange, activeListenerWithCapture);
558-
['pointerup', 'pointercancel'].forEach((eventName) => {
563+
['pointerup', 'pointercancel', 'pointerout'].forEach((eventName) => {
559564
swiper.wrapperEl.addEventListener(eventName, onGestureEnd, passiveListener);
560565
});
561566

@@ -572,7 +577,7 @@ export default function Zoom({ swiper, extendParams, on, emit }) {
572577
// Scale image
573578
swiper.wrapperEl.removeEventListener('pointerdown', onGestureStart, passiveListener);
574579
swiper.wrapperEl.removeEventListener('pointermove', onGestureChange, activeListenerWithCapture);
575-
['pointerup', 'pointercancel'].forEach((eventName) => {
580+
['pointerup', 'pointercancel', 'pointerout'].forEach((eventName) => {
576581
swiper.wrapperEl.removeEventListener(eventName, onGestureEnd, passiveListener);
577582
});
578583

0 commit comments

Comments
 (0)