Is it possible to implement "long press" in JavaScript (or jQuery)? How?
alt text http://androinica.com/wp-content/uploads/2009/11/longpress_options.png
HTML
<a href="" title="">Long press</a>
JavaScript
$("a").mouseup(function(){
// Clear timeout
return false;
}).mousedown(function(){
// Set timeout
return false;
});
Most elegant and clean is a jQuery plugin: https://github.com/untill/jquery.longclick/, also available as packacke: https://www.npmjs.com/package/jquery.longclick.
In short, you use it like so:
The advantage of this plugin is that, in contrast to some of the other answers here, click events are still possible. Note also that a long click occurs, just like a long tap on a device, before mouseup. So, that's a feature.
like this?
jQuery plugin. Just put
$(expression).longClick(function() { <your code here> });
. Second parameter is hold duration; default timeout is 500 ms.DEMO
You can check the time to identify Click or Long Press [jQuery]