【发布时间】:2013-11-23 09:24:37
【问题描述】:
我试图捕捉的“手势”是一个点击,当但仅当一个元素(其他或相同)已经触摸它时。因此,触摸 (1) 按下按钮,而触摸 (2) 轻按所选选项,触摸 (1) 释放并按下按钮。
我遇到的问题是最后一点。当我松开最后一根手指时,没有触发“touchend”事件?所以我没有办法按下按钮?
..“touchend”事件也总是有 touches.length = 0?
这里有一些代码,所以你可以明白我的意思。我认为这可能是移动 safari 中的一个错误?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Multi-touch problem</title>
<style>
#touchpane{
width:900px;
height:500px;
background-color:#333;
}
</style>
</head>
<body>
<div id="touchpane" click="void();"></div>
<script>
var tp = document.getElementById("touchpane");
tp.addEventListener('touchstart', function(e){
e.preventDefault();// to stop copy and paste
console.log("touchstart " + e.touches.length );
}, false)
tp.addEventListener('touchend', function(e){
console.log("touchend " + e.touches.length );
// not called when last finger removed?
}, false)
tp.addEventListener('touchcancel', function(e){
console.log("touchcancel");
}, false)
</script>
</body>
</html>
【问题讨论】:
-
确保包含您的操作系统版本。这在 3.1.3(第一代 iPod touch)中按预期工作:“touchstart 1”、“touchstart 2”、“touchend 1”、“touchend 0”。
-
当然很抱歉。 3.2.1 在 iPad 上。这和其他一些似乎已在 4.2 中修复
标签: javascript ipad cordova mobile-safari