我已经尝试了几种不同的方法来消除由于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>
发布于 2013-11-08 20:08:11
尝试使用下面的代码。
function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady()
{
alert('test');
FastClick.attach(document.body);
}如果一切正常,您应该能够看到警告框。
在http://phonegap-tips.com/articles/fast-touch-event-handling-eliminate-click-delay.html上看看
发布于 2013-11-08 20:12:45
我还能想到另一种解决方案..注意:我还没有亲自尝试过..
$(document).on('pageinit', '.ui-page', function (event, data)
{
FastClick.attach(activePage);
});发布于 2015-02-14 04:20:49
你应该在jQuery手机中使用内置的vclick event --和FastClick的想法一样。
$(document).on('vclick', '#someButton', function(){
});https://stackoverflow.com/questions/19849637
复制相似问题