Is it possible to get the duration of a touch using javascript on ios devices (and others if possible)? I would like to differentiate a long press from a short "click" press on an iphone webapp.
Thank you for your help!
$('#element').each(function() {
   var timeout,
       longtouch;
   $(this).bind('touchstart', function() {
      timeout = setTimeout(function() {
          longtouch = true;
      }, 1000);
   }).bind('touchend', function() {
       if (longtouch) {
          // It was a long touch.
       }
       longtouch = false;
       clearTimeout(timeout);
   });
});
jsFiddle.
The fiddle works with a long click.
Take a look at jQuery mobile http://jquerymobile.com/demos/1.0a4.1/#docs/api/events.html
It has tap, and taphold events, which sounds like it might fit your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With