Skip to content

Commit

Permalink
fix: skipSnaps fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xiel committed May 29, 2024
1 parent f4eabb7 commit 8fc0fd5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions embla-carousel-wheel-gestures/src/WheelGesturesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8fc0fd5

Please sign in to comment.