触摸事件不是在Android的PhoneGap的工作的WebView(甚至是内置的浏览器) [英] touch events not working in android phonegap webview (or even built-in browser)

查看:148
本文介绍了触摸事件不是在Android的PhoneGap的工作的WebView(甚至是内置的浏览器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的PhoneGap和使用'touchstart,以加快响应点击需要,才意识到,没有'touchstart','touchmove','touchend被解雇,但点击。

I was using phonegap and needed to use 'touchstart' to speed up click response, only to realize that none of 'touchstart', 'touchmove', 'touchend' is firing but 'click'.

我甚至在测试内置的浏览器(7的Andr​​oid 4.0.3平板电脑)一个简单的页面,发现它失败了。

I even tested a simple page in the built-in browser (7" android 4.0.3 tablet), and found it failed.

我在两片测试还是一样。
下页,按钮2只显示html_click,按钮3只显示点击

I tested on two tablets still the same. In the following page, button2 shows only 'html_click', button3 shows only 'click':

<!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf8">
    <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width">
    <title>Droid touch event test.</title>
    </head>
    <body>
    <button id="button">touch it</button>
    <button id="button2" ontouchstart="d_('html_touchstart')" onclick="d_('html_click')">html</button>
    <button id="button3">touch 3</button>
    <div id="db"></div>
    <script>
            function $(d){return document.getElementById(d)}
            function d_(m){dbo.innerHTML=dbo.innerHTML+' '+m}
            function ts1(e){d_('document touched')}
            function ts2(e){d_('button touched')}
            function eh(e){
                d_(e.type);
            }
            var ets='touchstart',dbo=$('db');
            document.addEventListener(ets,ts1,false);
            $('button').addEventListener(ets,ts2,false);
            $('button3').addEventListener(ets,eh,false);
            $('button3').addEventListener('touchend',eh,false);
            $('button3').addEventListener('click',eh,false);
    </script>
    </body>
    </html>

为什么'touchstart不点火?我应该怎么做任何事情,使触摸事件的工作?
或有任何其他方式做出回应点击快?

Why 'touchstart isn't firing? Should I do anything to make touch events work? Or is there any other way around to make click response faster?

我用鼠标按下事件工作,但不是特别快。

I used mousedown event, worked but not notably fast.

(新的Date())之间。的getTime()差异(包括一些的innerHTML 的变化)鼠标按下点击大约只有15。

(new Date()).getTime() difference (including some innerHTML change) between mousedown and click is only around 15.

推荐答案

只保留什么必要向你展示的概念,我在一个写这个,并使用PhoneGap的构建测试(默认为PhoneGap的2.0,但不应该的问题) ICS的设备。应为你工作:

Keeping only what was necessary to show you the concept, I wrote this and tested using Phonegap Build (default to Phonegap 2.0, but shouldn't matter) on an ICS device. Should work for you:

<!DOCTYPE html>
<html>
    <body>
        <button id="button1">1</button>
        <button id="button2">2</button>

        <script>
            document.getElementById("button1").addEventListener('touchstart',button1Pressed);
            document.getElementById("button2").addEventListener('touchstart',button2Pressed);
            function button1Pressed ()
            {
                alert('Button 1 Pressed');
            }

            function button2Pressed ()
            {
                alert('Button 2 Pressed');
            }
        </script>
    </body>
</html>

这篇关于触摸事件不是在Android的PhoneGap的工作的WebView(甚至是内置的浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆