为什么 touchmove 事件在移动端会触发多次甚至卡顿?

Mr-玉英 阅读 3

我在做一个滑动删除功能,监听了 touchstart 和 touchmove,但发现手指稍微一动就触发好多次 touchmove,而且页面还会卡一下。是不是我哪里写错了?

我试过用 e.preventDefault() 但好像没用,代码大概是这样:

element.addEventListener('touchmove', (e) => {
  const touch = e.touches[0];
  console.log('移动位置:', touch.clientX, touch.clientY);
  // 这里做了一些 DOM 操作
});
我来解答 赞 3 收藏
二维码
手机扫码查看
暂无解答

暂无解答