Javascript 拖放以重新排序 HTML 列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10361779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:01:59  来源:igfitidea点击:

Drag and drop to reorder HTML lists

javascriptuser-interfacedrag-and-drop

提问by nornagon

I have an app for which I would like to be able to drag and drop to reorder and arrange colours into groups. jQuery's sortablefor grids seems rather unresponsive and a little buggy. microjsrecommends kbjr's DragDrop, but that library has no concept of lists, only movable objects. Sproutcorehas a nice implementation, but I can't find a demo of it working for a grid.

我有一个应用程序,我希望能够对其进行拖放以重新排序并将颜色分组。jQuery对网格的排序似乎反应迟钝,而且有点问题。microjs推荐kbjr 的 DragDrop,但该库没有列表的概念,只有可移动的对象。Sproutcore有一个很好的实现,但我找不到它在网格上工作的演示。

My UI looks like this:

我的用户界面如下所示:

groups of colours

颜色组

and I'd like users to be able to drag colours around within the groups as well as drag them between groups.

我希望用户能够在组内拖动颜色以及在组之间拖动颜色。

回答by Farhadi

Try this: HTML5 Sortable. It is a jQuery plugin to create sortable lists and grids using native HTML5 drag and drop API.

试试这个:HTML5 Sortable。它是一个使用原生 HTML5 拖放 API 创建可排序列表和网格的 jQuery 插件。

回答by ahmohamed

Just a friendly update, since this question came up in the search. HTML5Sortable is no longer maintained. The recommended library is Sortable. Size: 12kb minified.

只是一个友好的更新,因为这个问题出现在搜索中。HTML5Sortable 不再维护。推荐的库是Sortable。大小:12kb 缩小。

Code:

代码:

var sortable = Sortable.create($('#items'));

Hope this help the next wanderer.

希望这对下一个流浪者有所帮助。

回答by adrianthedev

I found out that this(Nastable) is a little bit more usefull for it has nesting capabilities.

我发现这个( Nastable) 更有用一点,因为它具有嵌套功能。

UpdateActually ended up using thisplugin with more options.

更新实际上最终使用带有更多选项的这个插件。

Hope it helps. Cheers!

希望能帮助到你。干杯!