Swiperia
Reference

Event objects

MovementEvent and SwipeEvent.

MovementEvent

What a gesture did, with no reference to the DOM. Returned by movement().

PropertyTypeDescription
directionSwipeDirection | nullDominant axis of travel, null when the points are identical.
sourceVector2Where the gesture started.
targetVector2Where it ended.
deltaXnumberSigned horizontal travel. Positive is right.
deltaYnumberSigned vertical travel. Positive is down.
absXnumberMath.abs(deltaX).
absYnumberMath.abs(deltaY).
velocitynumberSpeed in pixels per millisecond.
vxvyVector2Signed velocity per axis.
distancenumberStraight-line distance between source and target, in pixels.

SwipeEvent

What a detector hands your callback: a MovementEvent plus the originating DOM event and the phase of the gesture.

PropertyTypeDescription
eventUIEventThe DOM event that produced this.
type'start' | 'move' | 'end' | 'cancel'The phase of the gesture.

Plus every MovementEvent property above.

swiper.listen((event) => {
  if (event.type !== 'end') return;
  event.event.preventDefault();
  console.log(event.direction, event.distance, event.velocity);
});

On a start event the gesture has not moved yet, so direction is null and every metric is 0source and target are the same point.

Narrowing on type is the idiomatic way to handle a gesture, since the payload shape is identical across all four phases.

On this page