jQuery plugin providing support for basic pointer events (mostly for <canvas>)
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
README.markdown
jquery.tappy.js

README.markdown

jQuery.Tappy

jQuery.Tappy is a small plugin that aims to provide support for basic pointer-based gestures (such as single and double clicks/taps, and dragging) to DOM elements that don't support them - or support poorly. The prime use is probably for the <canvas> element.

Usage

Once you initialize a DOM element with tappy(), you can bind handlers to events it generates:

$('canvas').tappy();
$('canvas').on('tap.tappy', canvas_tap);
$('canvas').on('doubletap.tappy', canvas_doubletap);

function canvas_tap(event) {
    var x = event.x, y = event.y;
    // ...
}

Events

All events reside in .tappy namespace. All coordinates received by event handlers are always relative to top-left corner of the tappy()'d DOM element.

  • move - Movement of the pointer. Event object contains x and y coordinates.
  • tap - Single tap/click. Event object contains x and y coordinates.
  • doubletap - Double tap/click. Event object contains x and y coordinates.
  • dragstart - Start of dragging, or mouse-down event. Event object contains x and y coordinates.
  • dragend - Start of dragging, or mouse-down event. Event object contains x and y coordinates.
  • drag - Drag event. Besides x and y coordinates, event object contains dx and dy values that are equal to movement of the pointer since the last drag event.

Options

tappy() accepts a non-mandatory argument: an object with options overriding plugin's default settings. These options are the following:

  • doubleTapEnabled - Whether double taps are detected and dispatches as events (they are by default). If false, values tapDistance and tapInterval are ignored.
  • tapDistance - Maximum distance (in pixels) between two subsequent taps/clicks that are to be counted as doubletap.
  • tapInterval - Maximum time interval (in milliseconds) between two subsequent taps/clicks that are to be counted as doubletap.