Skip to content

Commit

Permalink
fix(zoom): fix zoom stick on pointer out
Browse files Browse the repository at this point in the history
fixes #6396
  • Loading branch information
nolimits4web committed Feb 28, 2023
1 parent f998115 commit 6700980
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/modules/zoom/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});

Expand Down

0 comments on commit 6700980

Please sign in to comment.