最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unable to get the properties of touchstart event? - Stack Overflow

programmeradmin4浏览0评论

When I try to implement the below code:

$('.touchelement').bind({'touchstart':function(e){
    console.info(e.touches.item(0));
}});

It shows the output as undefined. Not only in touchstart, but for every other event like (touchmove, touchend) it shows the same result.

Is there is any alternate way to bind the touchstart event using jQuery.

When I try to implement the below code:

$('.touchelement').bind({'touchstart':function(e){
    console.info(e.touches.item(0));
}});

It shows the output as undefined. Not only in touchstart, but for every other event like (touchmove, touchend) it shows the same result.

Is there is any alternate way to bind the touchstart event using jQuery.

Share Improve this question edited Nov 7, 2020 at 10:06 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked May 30, 2011 at 7:24 SanthanamSanthanam 3484 silver badges15 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 19

jQuery does some processing on event objects to make them consistent across browsers, but it doesn't know about the touches array so this isn't copied to the new event object. So, you need to access it through the original event object which is event.originalEvent.

$('.touchelement').bind({'touchstart':function(e){
  console.info(e.originalEvent.touches[0]);
}});

Should it not look more like this?

$('.touchelement').bind('touchstart', function(e){
  console.info(e.touches);
});
发布评论

评论列表(0)

  1. 暂无评论