考虑在拖动过程中滚动,拖放列表中的项目的最佳方式是什么 在反应中考虑移动触摸操作,而不仅仅是电脑/笔记本电脑中的鼠标操作
<list>
<item1>
<item2>
<item3>
....
</list>
我用的是dnd-kit,相当稳定。您可以使用 PointerSensor 来处理单击和触摸操作。 这是我自己的代码片段:
return (
<DndContext collisionDetection={rectIntersection} onDragEnd={handleDragEnd} sensors={sensors}>
const DraggableGrid = ({ cards, selectedPhotos, handleDragEnd, handleCardClick, coloured_tags }) => {
const sensors = useSensors(
// Pointer sensor listens to mouse and touch events, distance is delay,
// eg, here drag will only be done after moving 8px of card, else touch events like checkbox won't work if drag is enabled
useSensor(PointerSensor, {
activationConstraint: {
distance: 8,
},
}),
);