You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TouchEvent#touches的文档记录范围是什么?是否存在0个触点场景?

TouchEvent.touches 的触点数量范围说明

触点数量的范围细节

  • 最小数量(0的场景):touches 数组长度可以为0,但仅会出现在 touchend 事件中——当最后一个触点离开屏幕时,touches 就会变成空数组。而在 touchstart 这类触点新增的事件里,touches 的长度至少为1,因为事件触发的前提就是有触点开始接触屏幕。

  • 最大数量:没有统一的标准上限,完全由设备的硬件触摸支持能力决定。比如不少现代移动设备支持5个及以上触点,MDN文档里的示例只处理到3个触点,只是为了简化演示逻辑,并非API本身的限制。

原示例代码说明

原示例仅做演示用,实际开发可根据设备支持情况扩展:

someElement.addEventListener('touchstart', (e) => {
   // Invoke the appropriate handler depending on the
   // number of touch points.
   switch (e.touches.length) {
     case 1: handle_one_touch(e); break;
     case 2: handle_two_touches(e); break;
     case 3: handle_three_touches(e); break;
     default: console.log("Not supported"); break;
   }
}, false);

内容的提问来源于stack exchange,提问作者Tristan F.-R.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 15:00:49