Swiperia

Introduction

What Swiperia is, and which package you need.

Swiperia is a small stack of libraries for swipe gestures on the web. It turns raw pointer and touch events into one consistent swipe event carrying direction, distance, velocity and the deltas along each axis.

The packages

Each package depends on the one above it, so installing swiperia-react gives you all three. You only install swiperia-core directly if you want the maths without any event handling.

The swipe event

Every detector reports the same four event types:

TypeWhen it fires
startthe gesture begins
moveon every movement while the gesture is tracked
endthe gesture finished and met the threshold and time constraints
cancelthe gesture finished but was too short or too slow to count

A start event carries zeroed metrics; every other type carries the full MovementEvent data.

A quick look

import { MouseSwiper, Swiper, TouchSwiper } from 'swiperia-js';

const swiper = new Swiper(element, [MouseSwiper, TouchSwiper]);

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

On this page