Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Mobile: catch "finger down" event

I need to detect the user "finger-press", there's already the "tap" event, but tap = press + release.

I need to call a JS function exactly on finger-press, exactly as keypress() does for standard browsers.

like image 652
Fabio B. Avatar asked Nov 25 '11 16:11

Fabio B.


2 Answers

There are a couple of events for that already.

They are vmousedown and taphold.

You can find a complete reference about them at this link:

http://jquerymobile.com/demos/1.0/docs/api/events.html

Basically, the jQuery Mobile framework maps the major "traditional" browser UI events prefixing them with a "v".

This is to signal that they are "virtual" events, in that by this mean you can catch events coming from standard (i.e. non-touch) and even touch-oriented devices as well.

So you could install a handler for a vmousedown event with:

$('#your-element-id').live('vmousedown', function() { alert("Hello") });

taphold, instead, is quite different: the event is triggered when a complete tap event takes place with a duration of nearly a second or more.

You can quickly play around with these two events to understand which one better fits your needs.

like image 168
Federico Zancan Avatar answered Oct 05 '22 22:10

Federico Zancan


Do you mean like taphold or vmousedown?

http://jquerymobile.com/demos/1.0/docs/api/events.html

like image 42
Alasjo Avatar answered Oct 05 '22 21:10

Alasjo