uni-app android touchmove 事件问题
uni-app android touchmove 事件问题
android 下 obj.addEventListener("touchmove", function(e) {
console.log(e.touches[0].clientX);
console.log(e.touches[0].clientY);
});
只会执行一次..手指并没有离开...在ios 下 就没有问题.
3 回复
android 下 obj.addEventListener(“touchmove”, function(e) {
console.log(e.touches[0].clientX);
console.log(e.touches[0].clientY);
e.preventDefault();//加个preventDefault然后测试
});
更多关于uni-app android touchmove 事件问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个Android平台下常见的touchmove事件触发问题。主要原因及解决方案如下:
- 问题原因:
- Android默认会优化touchmove事件,当检测到连续坐标变化不大时会减少触发频率
- 与iOS的事件处理机制存在差异
- 解决方案: (1) 使用@touchmove指令替代原生addEventListener:
<view [@touchmove](/user/touchmove)="handleTouchMove"></view>
(2) 在methods中添加处理函数:
handleTouchMove(e) {
console.log(e.touches[0].clientX);
console.log(e.touches[0].clientY);
}
- 如果必须使用原生事件监听,可以尝试:
obj.addEventListener("touchmove", function(e) {
e.preventDefault(); // 阻止默认行为
console.log(e.touches[0].clientX);
console.log(e.touches[0].clientY);
}, {passive: false}); // 禁用被动模式