Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需要检查触摸点的数量,touchScale方法报错undefined is not an object (evaluating 't.touches[1].clientX') #835

Open
cadiron opened this issue Jun 28, 2024 · 2 comments

Comments

@cadiron
Copy link

cadiron commented Jun 28, 2024

包版本1.1.3
机型:安卓
环境:微信环境
这个错误信息 undefined is not an object (evaluating 't.touches[1].clientX') 表示在JavaScript 代码中尝试访问 t.touches[1].clientX 时,t.touches[1] 是 undefined,即 t.touches 数组没有第二个元素。

这个问题的发生通常有以下几种情况:
没有足够的触摸点:当事件发生时,可能只有一个触摸点,但代码试图访问第二个触摸点。
事件触发时机不正确:某些事件类型在触摸点还未更新时被触发,导致访问的触摸点数组不完整。

建议修复为检查数量再访问:
element.addEventListener('touchmove', function (event) {
if (event.touches.length > 1) {
var touch1 = event.touches[0];
var touch2 = event.touches[1];
// 处理多点触控逻辑
} else {
console.log('只有一个触摸点');
}
});

@xyxiao001
Copy link
Owner

ok 我看看,在双指缩放时兼容处理下,如果只有一个触摸点,不走下面逻辑

@cadiron
Copy link
Author

cadiron commented Jun 28, 2024

好滴,谢谢大佬~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants