移动端手势滑动时 touchmove 事件不触发怎么办?

设计师楚萓 阅读 3

我在做一个移动端的滑动组件,监听了 touchstart 和 touchmove 事件,但发现有时候手指滑动了,touchmove 根本没触发,只触发了 touchstart 和 touchend。我试过在 touchstart 里加 event.preventDefault(),但还是不行。

这是我的监听代码:

element.addEventListener('touchstart', (e) => {
  console.log('start');
});

element.addEventListener('touchmove', (e) => {
  console.log('move'); // 这行经常不执行
});

element.addEventListener('touchend', (e) => {
  console.log('end');
});

是不是被浏览器默认行为拦截了?该怎么解决?

我来解答 赞 2 收藏
二维码
手机扫码查看
暂无解答

暂无解答