I'm trying to get the X position with jQuery of a touchstart event, used with the live function?

即.

$('#box').live('touchstart', function(e) { var xPos = e.PageX; } );

Now, this does work with 'click' as the event. How on earth (without using the alpha jQuery Mobile) do I get it with a touch event?

Any ideas?

Thanks for any help.

推荐答案

有点晚了,但是您需要访问原始事件,而不是jQuery消息传递的事件.此外,由于这些是多点触控活动,因此需要进行其他更改:

$('#box').live('touchstart', function(e) {
  var xPos = e.originalEvent.touches[0].pageX;
});

If you want other fingers, you can find them in other indices of the touches list.

UPDATE FOR NEWER JQUERY:

$(document).on('touchstart', '#box', function(e) {
  var xPos = e.originalEvent.touches[0].pageX;
});

Jquery相关问答推荐

Sheets从多张sheet中导入range匹配数据

为什么我的 toFixed() 函数不起作用?

输入类型=文件的jQuery更改方法

jQuery: Select 属性大于值的所有元素

如何使用 jQuery 搜索 JSON 树

如何使用jquery取消绑定所有事件

使用 JQuery 清除下拉列表

如何从 jQuery 中的父级中 Select 所有子级(任何级别)?

jQuery淡出不显示无?

使用 jQuery 从 JavaScript 对象中添加/删除项目

如何使用jQuery动态设置宽度和高度

AngularJS + JQuery:如何在 angularjs 中获取动态内容

使用 Typescript 时如何停止类型 JQuery 上不存在属性语法错误?

jQuery:如何找到第一个可见的输入/ Select /文本区域,不包括按钮?

Rails 5:如何将 $(document).ready() 与 turbo-links 一起使用

使用 JavaScript 获取用户代理

如何在调用 Ajax 等异步调用时让代码等待

如何禁用由子元素触发的 mouseout 事件?

粘性侧边栏:向下滚动时固定在底部,向上滚动时固定在顶部

jQuery:通过 .attr() 添加两个属性;方法