touchend事件属性

touchend event properties

本文关键字:属性 事件 touchend      更新时间:2023-09-26

如果我用从移动设备捕获所有触摸端事件

$(document.body).bind('touchend', function (e) {
var touch = e.touches[0]; // doesnt work
...

我需要从e参数中获取touch.screenX、touch.screeenY、touch.clientX和touch.clientX。我看到的所有例子都表明e.touches将是一个集合,您可以使用e.touches[0]了解触摸细节。在我的ipad测试中,e.touches总是未定义的。我没有使用任何jquery插件。

还尝试了e.targetTouches,它也是未定义的。

有人能帮忙吗?

实际上,释放的触摸会在changedTouches数组中找到,即:

e.changedTouches[0].pageX // get the end x page coordinate for a released touch

我认为这比通过originalEvent属性稍微可靠一些。

您可以在此处阅读有关changedTouches的更多信息:http://www.w3.org/TR/touch-events/#changedtouches-触摸事件的

touches属性是一个TouchList对象。您可以在此处看到TouchList类引用。

如果您在#log-div:上使用此示例代码监视其长度属性

$('#element').bind('touchstart', function(event) 
{
    $('#log').append(event.originalEvent.touches.length+'<br/>');
});
$('#element').bind('touchmove', function(event) 
{
    $('#log').append(event.originalEvent.touches.length+'<br/>');
});
$('#element').bind('touchend', function(event) 
{
    $('#log').append(event.originalEvent.touches.length+'<br/>');
});

执行touchstart和touchmove时将获得1,执行touchend时将获得0。这就是为什么您从e.touches[0]中获得undefined。