2

I am developing an app for a touchscreen and I would like to capture the equivalent of the mouse down and mouse up events.

For example, when the user has their finger touching the screen, a javascript function will execute, but when the finger leaves the screen function stops.

I am using firefox 3.5, with the jQuery framework for my javascript.

Thanks for any help, Ben

Globalz
  • 4,474
  • 6
  • 34
  • 43

4 Answers4

2

Just use jQuery mousedown and mouseup.

There are no specific events for using a finger, because all the finger actions do are to fire the mouse events on the page:

$(document).mousedown(function(e) {
   alert("Finger is Down");
});

$(document).mouseup(function(e) {
   alert("Finger is Up");
});
djdd87
  • 67,346
  • 27
  • 156
  • 195
  • This is what I originally tried before posting the question. The mouseup event doesnt get fired when the finger leaves the screen – Globalz Oct 01 '10 at 14:23
  • Perhaps you should updated your question with some code and show it now working. – djdd87 Oct 01 '10 at 14:29
1

The touchstart event fires when a finger touches the screen no matter if the user is going to tap or scroll. mousedown does not work in these cases.

$(document).on('touchstart', 'body', function(){
  alert("Screen touched");
});

I do not know any event that fires when a finger leaves the screen.

netAction
  • 1,827
  • 1
  • 18
  • 18
1

You are probably interested in the touchcancel event: https://developer.mozilla.org/en-US/docs/Web/Events/touchcancel.

ngryman
  • 7,112
  • 2
  • 26
  • 23
0

I think this jQuery plugin can help you.

Shikiryu
  • 10,180
  • 8
  • 49
  • 75