touchend 事件在滚动时为什么会误触发?
我在做一个移动端的滑动删除功能,绑定了 touchstart 和 touchend 来判断用户是否轻扫。但发现只要手指在列表上滚动一下,即使没抬起,也会触发 touchend,导致误删。这是为啥?
我试过加 e.preventDefault(),也检查了是不是冒泡问题,但都没用。下面是我给列表项加的样式:
.swipe-item {
touch-action: none;
-webkit-user-select: none;
user-select: none;
}
难道是 touch-action 设置不对?还是得配合其他手势判断?
FSD-颖杰
Lv1
我之前也遇到过。touchend 在滚动时被触发是因为滚动本身也会结束触摸。解决办法是在 touchstart 时记录一个时间戳,touchend 时判断如果时间差很小就认为是轻扫,否则忽略。代码如下:
点赞
2026-03-23 09:29
亚捷 Dev
Lv1
改成这样:
点赞
2
2026-02-24 16:05