Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rather than use <code>tap</code> and <code>taphold</code> (which I've tried to use but ran into the same problems, it seems to be an inherent issue with the <code>taphold</code> event) you can use <code>vmousedown</code> and set a flag, then bind to <code>vmouseup</code> to determine if it was a <code>tap</code> or a <code>taphold</code>:</p> <pre><code>var tapTime = 0; $('#my_item_'+items[idx].user_item_id).bind('vmousedown vmouseup', function (event) { if (event.type == 'vmousedown') { tapTime = new Date().getTime(); } else { //event.type == 'vmouseup' //here you can check how long the `tap` was to determine what do do var duration = (new Date().getTime() - tapTime); if (duration &gt; 3000) { //this is a tap-hold ShowMyItemInfo(items[idx]); } else { //this is a tap FitMyUpgradeItem(items[idx]); } } }); </code></pre> <p>For this to work properly you'll have to add an IIFE around the loop-code or change <code>ShowMyItemInfo(items[idx]);</code> to work without referencing the variable that changes each iteration of the loop. An easy to create an IIFE is to just use <code>$.each()</code>. Otherwise your loop would look something like this:</p> <pre><code>for(var idx in items) { (function (idx) { ... })(idx); } </code></pre> <p>IIFE = Immediately-Invoked-Function-Expression. It allows us to take a "snapshot" of the current state of variables we pass into the IIFE. So as we pass in <code>idx</code> (technically the second instance is the variable that's being passed in, and the first instance is the variable available inside the IIFE, which could be changed to something like <code>ids_new</code> for simplicity sake), the value passed in is saved for when the <code>tap</code> event handler fires.</p> <h1>Update</h1> <p>You can also set a timeout to determine <code>taphold</code> rather than using the <code>vmouseup</code> event:</p> <pre><code>//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; } }); </code></pre> <p>This way the event will fire after the user holds down their finger for three seconds. Then the <code>tap</code> event handler will only fire if that three seconds did not occur.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload