From 670098077d5209b76356486f95b623d3ee22228a Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Tue, 28 Feb 2023 18:04:26 +0300 Subject: [PATCH] fix(zoom): fix zoom stick on pointer out fixes #6396 --- src/modules/zoom/zoom.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/zoom/zoom.js b/src/modules/zoom/zoom.js index 486ed94ec..ba997a0bc 100644 --- a/src/modules/zoom/zoom.js +++ b/src/modules/zoom/zoom.js @@ -120,6 +120,9 @@ export default function Zoom({ swiper, extendParams, on, emit }) { // Events function onGestureStart(e) { + if (e.pointerType === 'mouse') { + evCache.splice(0, evCache.length); + } if (!eventWithinSlide(e)) return; const params = swiper.params.zoom; fakeGestureTouched = false; @@ -189,11 +192,13 @@ export default function Zoom({ swiper, extendParams, on, emit }) { } function onGestureEnd(e) { if (!eventWithinSlide(e)) return; + if (e.pointerType === 'mouse' && e.type === 'pointerout') return; const params = swiper.params.zoom; const zoom = swiper.zoom; const pointerIndex = evCache.findIndex((cachedEv) => cachedEv.pointerId === e.pointerId); if (pointerIndex >= 0) evCache.splice(pointerIndex, 1); + if (!fakeGestureTouched || !fakeGestureMoved) { return; } @@ -555,7 +560,7 @@ export default function Zoom({ swiper, extendParams, on, emit }) { swiper.wrapperEl.addEventListener('pointerdown', onGestureStart, passiveListener); swiper.wrapperEl.addEventListener('pointermove', onGestureChange, activeListenerWithCapture); - ['pointerup', 'pointercancel'].forEach((eventName) => { + ['pointerup', 'pointercancel', 'pointerout'].forEach((eventName) => { swiper.wrapperEl.addEventListener(eventName, onGestureEnd, passiveListener); }); @@ -572,7 +577,7 @@ export default function Zoom({ swiper, extendParams, on, emit }) { // Scale image swiper.wrapperEl.removeEventListener('pointerdown', onGestureStart, passiveListener); swiper.wrapperEl.removeEventListener('pointermove', onGestureChange, activeListenerWithCapture); - ['pointerup', 'pointercancel'].forEach((eventName) => { + ['pointerup', 'pointercancel', 'pointerout'].forEach((eventName) => { swiper.wrapperEl.removeEventListener(eventName, onGestureEnd, passiveListener); });