Instead of using tap and taphold (which I tried to use but faced with the same problems, this seems to be an inherent problem with the taphold event), you can use vmousedown and set the flag, then bind to vmouseup to determine if it was tap or taphold :
var tapTime = 0; $('#my_item_'+items[idx].user_item_id).bind('vmousedown vmouseup', function (event) { if (event.type == 'vmousedown') { tapTime = new Date().getTime(); } else {
For proper operation, you will need to add IIFE around the loop code or change ShowMyItemInfo(items[idx]); to work without a reference to a variable that changes each iteration of the loop. Easy to create IIFE - just use $.each() . Otherwise, your loop will look something like this:
for(var idx in items) { (function (idx) { ... })(idx); }
IIFE = Instantly call-function-expression. This allows us to take a “snapshot” of the current state of the variables that we pass to IIFE. Since we are going to idx (technically, the second instance is a variable that is passed inside, and the first instance is a variable available inside IIFE that can be changed to something like ids_new for simplicity), the value passed to is saved when it fires tap event handler.
Update
You can also set a timeout to define taphold instead of using the vmouseup event:
//setup a timer and a flag variable var tapTimer, isTapHold = false; $('#my_item_'+items[idx].user_item_id).bind('vmousedown vmouseup', function (event) { if (event.type == 'vmousedown') { //set the timer to run the `taphold` function in three seconds // tapTimer = setTimeout(function () { isTapHold = true; ShowMyItemInfo(items[idx]); }, 3000); } else { //event.type == 'vmouseup' //clear the timeout if it hasn't yet occured clearTimeout(tapTimer); //if the flag is set to false then this is a `tap` event if (!isTapHold) { //this is a tap, not a tap-hold FitMyUpgradeItem(items[idx]); } //reset flag isTapHold = false; } });
Thus, the event is triggered after the user holds his finger for three seconds. Then the tap event handler will fire only if these three seconds have not occurred.
Jasper
source share