Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tap event fired after taphold jQuery Mobile 1.1.1

I am developing an app for iOS using Phonegap bundled with jQuery Mobile 1.1.1. I have a div on my page that is listening for both tap and taphold events.

The problem I am facing is that the tap event is fired after the taphold event once I lift my finger. How do I prevent this? A solution is provided here but is this the only way to do this? Kinda nullifies the whole point of having two different events for tap & taphold if you need to use a boolean flag to differentiate the two.

Following is my code:

$('#pageOne').live('pageshow', function(event) {
    $('#divOne').bind('taphold', function (event) {
       console.log("TAP HOLD!!");    
    });

    $('#divOne').bind('tap', function () {
      console.log("TAPPED!!");
    });
});

Would greatly appreciate the help. Thanks!

like image 520
ares05 Avatar asked Oct 07 '22 01:10

ares05


1 Answers

Simply set this at the top of your document or anywhere before you define your even:

$.event.special.tap.emitTapOnTaphold = false;

Then you can use it like this:

$('#button').on('tap',function(){
    console.log('tap!');
}).on('taphold',function(){
    console.log('taphold!');
});
like image 67
Behnam Rasooli Avatar answered Oct 13 '22 12:10

Behnam Rasooli