我即将找到一个由 ghostCoder 提供的解决方案,它暗示了检测触摸事件而不是点击事件的想法。下面的代码是我目前拥有的代码,但是仍然不太正确。它适用于我的主页(非常基本的页面),但是它破坏了实际的游戏页面:
这是我的代码: 脚本:
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(首先显示开始按钮然后当点击显示停止按钮,然后再次开始等)
<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
。即使操作是 drag/scroll
,也会触发 touchstart
。
关于javascript - Android/phonegap - 点击响应时间慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9309433/