简体   繁体   English

跨平台 HTML touchend 事件处理

[英]Cross-platform HTML touchend event handling

In reading about the touchend event, it seem that the behavior is somewhat inconsistent across different devices.在阅读touchend事件时,似乎行为在不同设备上有些不一致。 I simply want to know the best and simplest way to determine whether all touching has ceased.我只是想知道确定所有触摸是否已停止的最佳和最简单的方法。 Do I understand correctly that I can't rely on event.touches being null or empty when this is the case because some devices will include the ended touch in that list?我是否正确理解在这种情况下我不能依赖 event.touches 为 null 或为空,因为某些设备将在该列表中包含结束的触摸? Do I understand correctly that I can't rely on changedTouches being the same length as touches when this is the case because some devices will exclude the ended touch from touches?我是否正确理解在这种情况下我不能依赖于changedTouches与触摸的长度相同,因为某些设备会从触摸中排除结束触摸?

For now only OSX (ipad, iphone) support ongesturechange event on their browser.目前只有 OSX(ipad、iphone)在浏览器上支持 ongesturechange 事件。 All the other events are supported in all devices, here are some of them and that is the way how to use them.所有设备都支持所有其他事件,以下是其中一些事件,这就是如何使用它们的方式。 To detect touch end you can use touchend even, it is the same over all devices and it will fires when all fingers are not in touch:要检测触摸结束,您甚至可以使用 touchend,它在所有设备上都是相同的,并且当所有手指都没有接触时它会触发:

$(someel).bind('touchend',callback');

To detect touch support just use this要检测触摸支持,只需使用它

var touchy=("ontouchstart" in document.documentElement)?true:false;

Safari developers ipad guide has a good documentation on this. Safari 开发人员 ipad 指南对此有很好的文档。

UPDATE: In fact I was wrong, touchend fires every time a finger lifts up: here is an excellent pdf for you: http://www.albanx.com/programing/ajaxupload/uploaded/SafariJSRef.pdf look at page 21.更新:实际上我错了,每次手指抬起时 touchend 都会触发:这里有一个很好的 pdf 给你: http : //www.albanx.com/programing/ajaxupload/uploaded/SafariJSRef.pdf查看第 21 页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM