使 jQuery 可排序项目可放置到其对等项
我有一个可排序的(任务)列表。它有助于确定任务的优先级,因此我想保留此功能。现在我想向功能添加子任务:我希望用户能够将一个任务拖到另一个任务并将其放到那里以将其变成子任务。
将 .draggable() 和 .droppable() 应用于已经可排序的项目没有任何效果。我能做什么?
I have a sortable list (of tasks). It helps prioritize tasks, so I want to keep this functionality. Now I want to add subtasks to the functionality: I want to enable users to drag one task over to another task and drop it there to turn it into a subtask.
Applying .draggable() and .droppable() to items that are already sortable has no effect. What could I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我整理了一个如何执行此操作的演示...但这可能不是最好的方法。以下是我发现的一些问题:
我确信有一种更好的方法,可以计算列表项的交集(就像可排序脚本一样)。但这是一种快速而肮脏的方法。
I put together a demo of how to do this... but it may not be the best method. Here are some problems I've discovered:
I'm sure there is a better method, one that calculates the intersection of list items (just like the sortable script does). But this is a quick and dirty method.
在我发布问题后,我没有耐心,我决定完全忽略 UI.sortable,从可拖动和可放置构建所需的功能,并使用特殊的 div 作为间隔符,这些间隔符会在拖动时膨胀以方便在任务之间插入。
这在某种程度上是有效的,只不过它的代码要多得多,而且比可排序更容易紧张和容易出错,即使将refreshPositions选项设置为true也是如此。尽管如此,可能还有其他正当理由想要规避 UI.sortable。
在非常简短的人造代码中:
$(.taskitem).draggable
revert: invalid
start: 动画间隔符高度从 0 到 5
$(.spacer).droppable
over:动画高度从 5 到 50
out:动画高度回到 5
drop:在 spacer 之后插入可拖动< /code>
找到与draggable索引相同的垫片并沿其移动
After I posted my question I had no patience, and I decided to ignore UI.sortable altogether, building the required functionality from draggable and droppable and using special divs as spacers that would swell up on dragover to facilitate dropping in between tasks.
That worked to some degree, except it's all much more code and it's a lot more jittery and bugprone than sortable, even with the refreshPositions option set to true. Still, there might be other valid reasons to want to circumvent UI.sortable.
In very brief faux code:
$(.taskitem).draggable
revert: invalid
start: animate height of spacers from 0 to 5
$(.spacer).droppable
over: animate height from 5 to 50
out: animate height back to 5
drop: insert draggable after spacer
find spacer with same index as draggable and move it along