javascript - Android/phonegap - 点击响应时间慢

标签 javascript android cordova timer

我即将找到一个由 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/

相关文章:

javascript - AngularJS slider - 路由问题(我无法正确路由我的按钮/页面)

Android adb shell ping - 此版本的 ping 不应以特权运行。中止

android - 创建非最终非静态类时出现NoClassDefFoundError

android - 使用 Phonegap/jQuery Mobile Android 和 iOS 应用程序下载文件并将其存储在本地

javascript - AngularJS ng-click 不会从 JQuery 代码中的动态按钮触发

javascript - Internet Explorer 8 中的大写标签

javascript - 哪个 webpack devtool 适合 chrome 应用程序?

android - 如何从 C++ 中的单独线程发布要在 Android 主线程上运行的代码?

javascript - Phonegap deviceNotReady 事件?

ios - PhoneGap/ChildBrowser-将应用程序表单发布到ChildBrowser