1

如何在 touchmove 期间获取手指下元素的 id?

我想要实现的是:

  • 绑定触摸[开始|结束|移动]
  • 在 touchstart 开始选择
  • 在 touchmove 期间,收集我手指下“触摸”的所有 dom 元素

示例代码

var collected = [];
$('body').bind('touchstart touchmove touchend', function(event) {
  event.preventDefault();
  if(event.type == 'touchstart') {
    collected = [];
  } else if(event.type == 'touchmove') {
    // id of the element under my finger??
    // insert in collected the id of the element
  } else if(event.type == 'touchend') {
    // some code
  }
});

解决了。

4

1 回答 1

1

您可以在此处找到有关 Safari 中所有触摸事件的信息。jQuery 没有任何触摸事件处理程序,您需要自己定义它们。取自这个stackoverflow帖子

document.addEventListener('touchmove', function(e) {
    e.preventDefault();
    var touch = e.touches[0];
    alert(touch.pageX + " - " + touch.pageY);
}, false);

通过这种方式,您可以定义所有触摸手势的方式。

于 2012-11-19T17:44:32.267 回答