reactjs – React-DnD中是否有任何选项,它可以根据拖拽对象启用
发布时间:2020-12-15 20:32:14 所属栏目:百科 来源:网络整理
导读:我一直在研究react-dnd(拖放组件).因此,基于鼠标指针识别远滴目标,我想知道是否有任何选项可以更改它,根据拖动对象需要识别的放置目标超过掉落目标的50%. 这与jQuery UI拖放功能类似,后者在droppable元素中包含“tolerance:intersect”. 解决方法 查看Reac
我一直在研究react-dnd(拖放组件).因此,基于鼠标指针识别远滴目标,我想知道是否有任何选项可以更改它,根据拖动对象需要识别的放置目标超过掉落目标的50%.
这与jQuery UI拖放功能类似,后者在droppable元素中包含“tolerance:intersect”. 解决方法
查看React-DnD的
sortable example,特别是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; } }; 我认为这两行是您正在寻找的: // Dragging downwards if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) { return; } // Dragging upwards if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) { return; } 它会在悬停时检查,如果您悬停的项目已超过移动项目的50%阈值,则它将执行重新排序操作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |