我正在使用 .on("touchstart mousedown",function (e) {pTouchDown(e)});
用一根手指触摸就可以了,但我也想用两根手指触摸做一些操作。
最佳答案
触摸事件包含一个名为touches
的属性,它包含所有可用的触摸点。您可以阅读有关 TouchEvents 的更多信息 on MDN.
在您的情况下,您需要检查 touches
属性的长度:
someElement.addEventListener('touchstart', function (e) {
if(e.touches.length > 1) {
// ... do what you like here
}
});
或者使用 jQuery:
$someElement.on('touchstart', function (e) {
if (e.touches.length > 1) {
// ... do what you like here
}
});
关于javascript - 如何在 javascript 中的 touchstart 检测两个手指?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24567441/