Nav & Search

quickGestures

I needed a quick and easy way to capture clicks and touch events in jQuery for some of my plugins and web projects so I made this jQuery plugin. It’s currently quite rough but it satisfies my needs, one of the main features is that the behavious can be tailored to mobile and non-mobile platforms.

It binds touch/click gestures and functions defined in the options object to an element. Currently supported gestures are drag left, drag right, click in the left and right half of the element, tap (when nothing is bound to click left or right) and hold. The plugin works in two modes, “normal” using mouse clicks and mobile where it captures touch events. It returns the element so that it can be chained.

Usage

jQuery(element).quickGestures(options-object)

For example, to bind clicks on the left side of an image to hide itself:

$("#img-hide").quickGestures({
    clickLeft: function() {$(this).hide()}
});

Options

Default value inside the parenthesis:

  • dragLeft (null): Function to perform if the mouse is clicked and dragged to the left (or left swipe)
  • dragRight (null): Function to perform if the mouse is clicked and dragged to the right (or right swipe)
  • clickLeft (null): Function to perform if the mouse is clicked on the left side of the element
  • clickRight (null): Function to perform if the mouse is clicked on the right side of the element
  • tap (null): Function to perform if no clickLeft or clickRight action is defined and mouse is clicked (or user taps) inside the element
  • hold (null): Function to perform if the mousebutton is pressed down for HoldTime or longer
  • holdtime (800): The time in milliseconds used for hold
  • threshold (50): The number of pixels used for threshold for dragLeft and dragRight
  • platformMode (“auto”): If platformMode is set to auto (which is the default) the user agent string is checked for mobile touch platforms, if set to “mobile” it captures touch events instead of mouse clicks

Download

Current version is 1.0, jquery.quickGestures.1.0.zip