Android / phonegap - click response time is slow

I'm close to developing a solution, kindly provided by ghostCoder, alluding to the idea of โ€‹โ€‹detecting a touch event rather than a click event. This code below is what I have now, however something else is not quite right. It works on my homepage (a very simple page), however it breaks with the actual game page:

Here is my code: JAVASCRIPT:

var b=document.getElementById('STOP'),start=0; //Check for touchstart if('ontouchstart' in document.documentElement) { document.getElementById("notouchstart").style.display = "none"; } //Add a listener that fires at the beginning of each interaction [b].forEach(function(el){el.addEventListener('touchstart',interact);}); //Add the event handlers for each button b.addEventListener('touchstart',highlight); //Functions Store the time when the user initiated an action function interact(e) { start = new Date(); } //Highlight what the user selected and calculate how long it took the action to occur function highlight(e) { e.preventDefault(); e.currentTarget.className="active"; if(start) { alert("test") } start = null; } 

BODY BUTTONS (first displays the start button, and then when the stop button is pressed, it stops, then it starts again, etc.)

  <INPUT TYPE="button" style="background:url(images/Start_Btn.png); background-color:transparent; width:150px; height:186px; border:none; cursor:pointer;" id="START" onClick="startBTN();"> <INPUT TYPE="button" style="background:url(images/Stop_Btn.png); background-color:transparent; width:150px; height:186px; border:none; cursor:pointer;" id="STOP"> 

Thanks,

+7
source share
5 answers

Listen to "touchstart instead of" click :) the click is slightly delayed in touch screens. Http://floatlearning.com/2011/03/developing-better-phonegap-apps/

+4
source

I used touchend for this. touchstart starts even if the drag/scroll action.

+9
source

Do not use buttons. If you add an event to the div, it will be faster.

0
source

I am working on a calculator, and my first idea was to start with a telephone conversation. Now I highly recommend not to do this when clicking on the buttons is time critical. Even if you disable all additional touch handlers and configure touchstart directly in the div: it is too slow. (touchhend will not do, by the way, it is called when you release your finger from the button)

0
source

In the Phonegap application, the click event has 300 ms delay time. Why don't you use the Fastclick library for this dusting ??? I tried and it works great!

https://github.com/ftlabs/fastclick

Hope is helpful

0
source

All Articles