How to use FastClick.js with Phonegap and JQM?

user2400026 picture user2400026 · Nov 8, 2013 · Viewed 15.4k times · Source

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>

Answer

Purus picture Purus · Nov 8, 2013

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