如何使用FastClick.js与Phonegap和JQM? [英] How to use FastClick.js with Phonegap and JQM?

查看:120
本文介绍了如何使用FastClick.js与Phonegap和JQM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几种不同的方法来消除300ms的延迟,因为webkit浏览器处理触摸事件。库,FastClick.js,似乎是首选的方法,但我有一点麻烦实现它。我已经包括它,并且还添加了一个事件监听器,但我不知道我是否正确添加了监听器。这应该是工作还是我没有做某事?
谢谢!



请考虑下面的代码,其中

  !DOCTYPE html> 
< html>
< head>
< title>
Calculator
< / title>
< meta name =viewportcontent =width = device-width,initial-scale = 1.0,maximum-scale = 1.0,user-scalable = no;>
< meta charset =utf-8>
< script type =text / javascriptcharset =utf-8src =phonegap.js>
< / script>
<< script type ='application / javascript'src ='js / fastclick.js'>< / script>
< script type =text / javascript>

function onBodyLoad()
{
document.addEventListener(deviceready,onDeviceReady,false);
$(function(){
FastClick.attach(document.body);
});

}

function onDeviceReady()
{


}
< / script>
< script>
window.addEventListener('load',function(){
new FastClick(document.body);
},false);
< / script>

< link rel =stylesheethref =./ css / jquerymobile.csstype =text / css>
< link rel =stylesheethref =./ css / jquerymobile.nativedroid.csstype =text / css>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< / head>

< body onload =onBodyLoad()>
<! - 第1页开头 - >
< div data-role =pagedata-theme ='b'id =one>
< div data-role =content>
< a href =#onedata-transition =nonedata-
< / div>
< / div>
< / body>

解决方案>

尝试下面的代码。

  function onBodyLoad()
{
document.addEventListener (deviceready,onDeviceReady,false);

}

function onDeviceReady()
{
alert('test');
FastClick.attach(document.body);
}

如果一切正常,您应该可以看到警告框。 / p>

查看 http://phonegap-tips.com/articles/fast-touch-event-handling-eliminate-click-delay.html


I've tried a few different ways to remove the 300ms delay due to the webkit browsers handling of touch events. The library, FastClick.js, seems to be the preferred method, yet I'm having a little trouble implementing it. I've included it and also added an event listener, but I don't know if I've added the listener correctly. Should this be working or am I failing to do something? Thank you!

Consider the code below, where

<!DOCTYPE html>
<html>
<head>
    <title>
        Calculator
    </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-   scale=1.0, user-scalable=no;">
    <meta charset="utf-8">
    <script type="text/javascript" charset="utf-8" src="phonegap.js">
    </script>
    <<script type='application/javascript' src='js/fastclick.js'></script>
    <script type="text/javascript">

    function onBodyLoad()
    {       
        document.addEventListener("deviceready", onDeviceReady, false);
         $(function() {
         FastClick.attach(document.body);
         });

    }

    function onDeviceReady()
    {


    }
    </script>
    <script>
                window.addEventListener('load', function() {
                new FastClick(document.body);
                }, false);
    </script>

    <link rel="stylesheet" href="./css/jquerymobile.css" type="text/css">
    <link rel="stylesheet" href="./css/jquerymobile.nativedroid.css" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">   
</head>

<body onload="onBodyLoad()">
    <!--START OF PAGE 1-->
    <div data-role="page" data-theme='b' id="one">
        <div data-role="content">
              <a href="#one" data-transition="none" data-
        </div>
    </div>
</body>

解决方案

Try with the below code.

function onBodyLoad()
{       
    document.addEventListener("deviceready", onDeviceReady, false);

}

function onDeviceReady()
{
  alert('test');
  FastClick.attach(document.body);
}

If everything is fine, you should be able to see the alert box.

Have a look on http://phonegap-tips.com/articles/fast-touch-event-handling-eliminate-click-delay.html

这篇关于如何使用FastClick.js与Phonegap和JQM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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