如何使用 JavaScript 或 jQuery 一次拖动多个元素?
我希望能够使用 jQuery 拖动一组元素,就像我在 Windows 桌面上选择并拖动多个图标一样。
我找到了tridubmedia的jQuery.event.drag的演示:
http: //tridubmedia.com/code/event/drag/demo/multi
我
认为这个插件太棒了。这是一个优秀且受欢迎的图书馆吗?您知道使用它的网站或应用程序吗?
是否有其他库或插件可以拖动多个对象?
jQuery UI 可以拖动多个对象吗?
I want to be able to drag a group of elements with jQuery, like if I selected and dragged multiple icons on the Windows desktop.
I found the demo of threedubmedia's jQuery.event.drag:
http://threedubmedia.com/code/event/drag/demo/multi
http://threedubmedia.com/code/event/drag#demos
I think this plugin is great. Is this good and popular library? Do you know websites or applications which use it?
Are there any other libraries or plugins to drag multiple objects?
Can jQuery UI drag multiple objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我是 Threedubmedia 插件的作者。我添加此功能是为了支持多个元素,因为我在其他地方找不到令人满意的解决方案。
如果您需要一个适用于 jQuery UI 的解决方案,这里有一个插件,它添加了一些多拖动功能,尽管演示似乎在 Firefox for Mac 中无法正常工作。
http://www.myphpetc.com/2009/ 11/jquery-ui-multiple-draggable-plugin.html
I am the author of the of the threedubmedia plugins. I added this functionality for supporting multiple elements, because I could not find a satisfactory solution anywhere else.
If you need a solution that works with the jQuery UI, here is a plugin which adds some multi-drag functionality, though the demos don't seem to work correctly in Firefox for Mac.
http://www.myphpetc.com/2009/11/jquery-ui-multiple-draggable-plugin.html
这对我有用。
在这里摆弄:
感谢 ChrisThompson 和 green 提供了近乎完美的解决方案。
This worked for me.
Fiddle here:
Thanks to ChrisThompson and green for the almost-perfect solution.
我想补充一下(这在谷歌中排名很高),因为这个线程中的插件都不起作用,而且它不是 jquery ui 支持的原生,这是一个简单而优雅的解决方案。
将可拖动元素包装在容器中,并使用事件一次拖动它们,这允许单个可拖动元素和多重可拖动元素(但不是真正的选择性可拖动元素)。
I wanted to add (this coming up high in google), since none of the plugins in this thread worked and it is not nativity supported by jquery ui, a simple elegant solution.
Wrap the draggable elements in a container and use an event to drag them all at once, this allows for singles draggables and multidraggables (but not really selective draggables).
看看这个:
https://github.com/someshwara/MultiDraggable
用法:
$(" .className").multiDraggable({ group: $(".className")});
将元素组拖动到一起。组也可以是指定各个元素的数组。
如:
$("#drag1").multiDraggable({ group: [$("#drag1"),$("#drag2") ]});
Check this out:
https://github.com/someshwara/MultiDraggable
Usage:
$(".className").multiDraggable({ group: $(".className")});
Drags the group of elements together. Group can also be an array specifying individual elements.
Like:
$("#drag1").multiDraggable({ group: [$("#drag1"),$("#drag2") ]});
将您的物品放入某个容器中,并使该容器可拖动。您需要将
handle
选项设置为 item 元素的类。此外,您还需要在拖动后重新计算项目位置。显然,当您取消选择项目时,您必须将它们从该容器中取出并放回原处。Put your items into some container and make this container draggable. You will need to set
handle
option to be a class of your item element. Also you will need to recalculate items position after drag. And obviously when you deselect items you have to take them from this container and put back to their origin.这就是我使用的,在我的情况下有效。
};
This is what i used, Worked in my case.
};
jquery UI 中有 Draggable
您所要做的就是:
参见此处的示例:http://jsfiddle.net/maniator/zVZFq/
如果你真的想要多重拖动,您可以尝试使用一些点击事件将块固定到位,
请参阅此处的示例: http://jsfiddle .net/manianator/zVZFq/5
there is Draggable in the jquery UI
all you would have to do is:
see example here: http://jsfiddle.net/maniator/zVZFq/
If you really want multidragging you can try using some click events to hold the blocks in place
See example here: http://jsfiddle.net/maniator/zVZFq/5