Longpress is a jQuery plugin that makes it easy to support long press events on mobile devices and desktop borwsers.
If you want something native and more low level than the jQuery implementation, take a look at longpress.js that is also written by me.
<script type="text/javascript" src="jquery.longpress.js"></script>
$('#button').longpress(function() {
// longpress callback
alert('You just longpress-ed a button.');
});
.longpress(longpressHandler(event)[, shortpressHandler(event), duration])
longpressHandler(event) | Required | Type: Function() A function to execute each time someone longpresses something. |
shortpressHandler(event) | Optional | Type: Function() A function to execute each time someone releases the mouse or touch before the longpress duration elapses. |
duration | Optional | Type: Integer longpress duration in milliseconds. |
Example:
$('#button').longpress(function(e) {
alert('You just longpressed something.');
}, function(e) {
alert('You released before longpress duration and that\'s why its a shortpress now.');
});
Copyright (c) 2008-2013, Vaidik Kapoor (kapoor [dot] vaidik -[at]- gmail [dot] com)