Raj*_*ana 7 javascript android timer cordova
由于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;
}
Run Code Online (Sandbox Code Playgroud)
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">
Run Code Online (Sandbox Code Playgroud)
谢谢,
监听 \xe2\x80\x98touchstart\xe2\x80\x99 而不是 \xe2\x80\x98click\' :)
点击在触摸屏中有点延迟。\n http://floatlearning.com/2011/03/developing-更好的phonegap应用程序/
| 归档时间: |
|
| 查看次数: |
11858 次 |
| 最近记录: |