由于webkit浏览器处理触摸事件,我尝试了几种不同的方式来消除300ms的延迟.图书馆,FastClick.js,似乎是首选方法,但我有一点麻烦实现它.我已经包括它,并添加了一个事件监听器,但我不知道我是否正确添加了监听器.这应该是工作还是我不做某事?
谢谢!
谢谢!
考虑下面的代码,在哪里
<!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>
解决方法
尝试以下代码.
function onBodyLoad() { document.addEventListener("deviceready",false); } function onDeviceReady() { alert('test'); FastClick.attach(document.body); }
如果一切正常,您应该可以看到警报框.
看看http://phonegap-tips.com/articles/fast-touch-event-handling-eliminate-click-delay.html