vee*_*n V 6 drag-and-drop jquery-ui reactjs react-dnd
我一直在研究react-dnd(拖放组件).因此,基于鼠标指针识别远滴目标,我想知道是否有任何选项可以更改它,根据拖动对象需要识别的放置目标超过掉落目标的50%.
这与jQuery UI拖放功能类似,后者在droppable元素中包含"tolerance:intersect".
查看React-DnD 的可排序示例,特别是其中的悬停功能cardTarget:
const cardTarget = {
hover(props, monitor, component) {
const dragIndex = monitor.getItem().index;
const hoverIndex = props.index;
// Don't replace items with themselves
if (dragIndex === hoverIndex) {
return;
}
// Determine rectangle on screen
const hoverBoundingRect = findDOMNode(component).getBoundingClientRect();
// Get vertical middle
const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
// Determine mouse position
const clientOffset = monitor.getClientOffset();
// Get pixels to the top
const hoverClientY = clientOffset.y - hoverBoundingRect.top;
// Only perform the move when the mouse has crossed half of the items height
// When dragging downwards, only move when the cursor is below 50%
// When dragging upwards, only move when the cursor is above 50%
// Dragging downwards
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
return;
}
// Dragging upwards
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
return;
}
// Time to actually perform the action
props.moveCard(dragIndex, hoverIndex);
// Note: we're mutating the monitor item here!
// Generally it's better to avoid mutations,
// but it's good here for the sake of performance
// to avoid expensive index searches.
monitor.getItem().index = hoverIndex;
}
};
Run Code Online (Sandbox Code Playgroud)
我认为这两行就是您正在寻找的:
// Dragging downwards
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
return;
}
// Dragging upwards
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
return;
}
Run Code Online (Sandbox Code Playgroud)
它会在悬停时检查悬停的项目是否超过了移动该项目的 50% 阈值,然后它将执行重新排序操作。
| 归档时间: |
|
| 查看次数: |
1301 次 |
| 最近记录: |