问题
I have images in grid form something like this
I am well aware of react dnd and it uses hover to get the positions and swap accordingly.
What I want
: Swap 1 with 4 and 4 with 1
What is happening:
While moving image 1 I am hovering it from 2 and 3 so the images in between are getting swapped here
I have modified my moveCard function to match my requirement.
const moveCard = useCallback((dragIndex, hoverIndex) => {
const dragCard = cards;
[dragCard[dragIndex], dragCard[hoverIndex]] = [
dragCard[hoverIndex],
dragCard[dragIndex]
];
setCards([...dragCard]);
});
Any help will be appreciated. All I want is to swap only 2 images that I am dragging and which I dropping, the rest images should not change their position.
来源:https://stackoverflow.com/questions/64913638/how-to-swap-two-cards-without-changing-position-other-cards