jquery.swipe.js

This file contains functions that handle all touch, pointer and click events and trigger unified touch events.

Demo page

Usage

jquery.swipe.js requires jquery.touch.js on the same page.

Use the following code to add swipe handler to a jQuery object.

$("#touch-target").swipe(function(direction) {
    // your handler code
});

Options

Options can be passed via an optional argument.

$("#touch-target").swipe(
    function(direction) {
        // your handler code
    },
    {
        preventDefault: true,
        mouse: true,
        pen: true,
        distance: 50
    });
Name Type Default Description
preventDefault boolean true prevent default click/touch handlers
mouse boolean true Whether swipe event should be triggered from mouse events.
pen boolean true Whether swipe event should be triggered from pen input.
distance number 50 The distance for a touch point to travel before triggering a swipe.

The handler argument

A direction argument will be passed into the handler function when it's called.
It will be a string type and have one of the eight values representing the direction of the swipe. The possible values are "left", "upleft", "up", "upright", "right", "downright", "down" or "downleft".