【问题标题】:jquery touchmove chrome mobilejquery touchmove chrome 手机
【发布时间】:2012-11-21 07:02:40
【问题描述】:

如何在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
  }
});

解决了。

【问题讨论】:

  • @Daneb:你最后是怎么解决的,能发一下你的解决方案吗?

标签: jquery google-chrome touchmove


【解决方案1】:

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

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

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

【讨论】:

  • touchstart 和 touchend 被正确触发; touchmove 应该是一样的,还是不一样?
  • 是的,应该是这样。否则你正在处理一个错误
  • 好的,现在我可以得到触摸的 [x,y] 坐标,我如何定位元素?
  • 好的,现在我可以使用 $(document.elementFromPoint(touch.pageX, touch.pageY)) 获取元素 id,它在默认的 android 浏览器和 opera 中运行良好;但不在 Chrome 中;有什么建议可以解决吗?似乎它在“不同”位置找到了元素
  • 已保存!惊人的!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2014-05-07
  • 2014-05-16
  • 1970-01-01
  • 2014-05-15
  • 2015-12-25
相关资源
最近更新 更多