在安卓系统中,如何在Javascript中捕捉点击但不滚动?
我正在制作一个Javascript web应用程序,我一辈子都无法启动在安卓系统中,如何在Javascript中捕捉点击但不滚动?,javascript,android,dom-events,touch-event,Javascript,Android,Dom Events,Touch Event,我正在制作一个Javascript web应用程序,我一辈子都无法启动touchstart事件。我得到的touchmove和touchend事件没有问题。这是一个问题,因为在我看来,区分轻触和滚动运动的最佳方法是将touchstart事件上的计数器归零,在touchmove更新它,然后在touchend比较它。我这样做是为了在点击结束时做一些动作,而不是滚动。例如,如果在完成向下滚动列表后为列表中的某个项目打开了一个页面,这将非常令人困惑,但如果能够点击某个项目以打开其页面,那将非常好 这就是我
touchstart
事件。我得到的touchmove
和touchend
事件没有问题。这是一个问题,因为在我看来,区分轻触和滚动运动的最佳方法是将touchstart
事件上的计数器归零,在touchmove
更新它,然后在touchend
比较它。我这样做是为了在点击结束时做一些动作,而不是滚动。例如,如果在完成向下滚动列表后为列表中的某个项目打开了一个页面,这将非常令人困惑,但如果能够点击某个项目以打开其页面,那将非常好
这就是我所拥有的:
// FIXME: this doesn't seem to ever fire
el.addEventListener('touchstart', function(e) {
// make sure that at the start of every touch we're not considered to be moving
alert("Touch starting");
app.__touchMoving = 0;
}, false);
el.addEventListener('touchmove', function(e) {
app.__touchMoving++;
}, false);
el.addEventListener('touchend', function(e) {
alert("Touch ended. We moved beforehand this many times: " + app.__touchMoving);
// if we are moving
if (app.__touchMoving > 0) {
// stop, since we're dragging, not tapping
return false;
}
// else we're no longer moving, so it was a tap
}
我从未看到touchstart
警报。如果我滚动touchend
将启动,并且app\uuu touchMoving将具有某种适当的价值。另一方面,我注意到有时候touchend
似乎会多次启动
我是不是错过了一些基本的东西?很多人说,这在Android(和iPhone)上应该可以很好地工作,但第一个听众似乎从来没有被激发过
更新:我应该提到我已经在运行Android 2.1的三星Galaxy S上进行了测试。我不知道你是否可以使用它:你的代码每晚在我的Nexus One/CyanogenMod上运行得很好(除了缺少一个
)
最后定义了el
和应用程序
)。它可以检测touchstart、move和end,并正确报告“移动”次数。太好了,正是我想听的-p我一直在运行2.1的Galaxy S上测试。