Android/phonegap-点击响应时间慢

Android/ phonegap - Click response time slow

本文关键字:响应时间 phonegap- Android      更新时间:2023-09-26

由于ghostCoder暗示了检测触摸事件而不是点击事件的想法,我即将制定出一个解决方案。下面的代码是我目前所拥有的,但是有些地方仍然不太正确。它在我的主页上运行(非常基本的页面),但在实际的游戏页面上它会崩溃:

这是我的代码: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;
}

机身按钮(首先显示启动按钮,然后单击时显示停止按钮,然后再次启动等)

    <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">

谢谢,

我为此使用了touchend。即使动作是CCD_ 3,CCD_。

听'touchstart'而不是'click':)
点击在触摸屏中有点延迟。http://floatlearning.com/2011/03/developing-better-phonegap-apps/

不要使用按钮。如果将事件添加到div中,速度会更快。

我正在开发一个计算器,我的第一个想法是从phonegap开始。现在,我强烈建议在按钮按下时间紧迫时不要这样做。即使禁用了所有额外的触摸处理程序并将touchstart直接设置为div:这也太慢了。(顺便说一句,触摸端不行,当你把手指从按钮上松开时就会调用它)

在Phonegap应用程序中,单击事件的延迟时间为300ms。你为什么不使用Fastclick库来实现这个目的???我试过了,效果很好!

https://github.com/ftlabs/fastclick

希望对有帮助