我正在使用移动设备的触摸事件:
const [draggedImage, setDraggedImage] = useState(null);
const handleTouchStart = (index) => {
setDraggedImage(index);
};
const handleTouchMove = (e, index) => {
e.preventDefault();
if (draggedImage === null || draggedImage === index) {
return;
}
const updatedImages = [...images];
const [movedImage] = updatedImages.splice(draggedImage, 1);
updatedImages.splice(index, 0, movedImage);
setImages(updatedImages);
setDraggedImage(index)
};
const handleTouchEnd = (e) => {
setDraggedImage(null);
};
handle-touch-move 的索引没有返回所需的输出?因为它应该返回图像索引,即图像所在的位置,或者对于此问题还有其他好的事件吗?
也许我是错的,但是触摸事件会传递
event
对象 触摸事件
如何将此函数传递到组件事件道具中?您可以复制并粘贴此代码吗?您是否通过 Chrome 开发工具对此进行测试,请链接如何测试此事件 -> 如何在浏览器中模拟触摸手势?