From 8fc0fd583170919cda13825909bb1a576a4cf36a Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Wed, 29 May 2024 08:31:02 +0200 Subject: [PATCH] fix: skipSnaps fixes --- .../src/WheelGesturesPlugin.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/embla-carousel-wheel-gestures/src/WheelGesturesPlugin.ts b/embla-carousel-wheel-gestures/src/WheelGesturesPlugin.ts index 29b1658..55bbecc 100644 --- a/embla-carousel-wheel-gestures/src/WheelGesturesPlugin.ts +++ b/embla-carousel-wheel-gestures/src/WheelGesturesPlugin.ts @@ -108,17 +108,18 @@ export function WheelGesturesPlugin(userOptions: WheelGesturesPluginType['option ;[moveY, moveX] = state.axisMovement } - // prevent skipping slides (X axis) - const noSkipSnapsMoveX = - moveX < 0 ? Math.max(moveX, -engine.containerRect.width) : Math.min(moveX, engine.containerRect.width) + // prevent skipping slides + if (!engine.options.skipSnaps && !engine.options.dragFree) { + const maxX = engine.containerRect.width + const maxY = engine.containerRect.height - // prevent skipping slides (Y axis) - const noSkipSnapsMoveY = - moveY < 0 ? Math.max(moveY, -engine.containerRect.height) : Math.min(moveY, engine.containerRect.height) + moveX = moveX < 0 ? Math.max(moveX, -maxX) : Math.min(moveX, maxX) + moveY = moveY < 0 ? Math.max(moveY, -maxY) : Math.min(moveY, maxY) + } return new MouseEvent(type, { - clientX: startEvent.clientX + (engine.options.skipSnaps ? moveX : noSkipSnapsMoveX), - clientY: startEvent.clientY + (engine.options.skipSnaps ? moveY : noSkipSnapsMoveY), + clientX: startEvent.clientX + moveX, + clientY: startEvent.clientY + moveY, screenX: startEvent.screenX + moveX, screenY: startEvent.screenY + moveY, movementX: moveX,