拖动多个选定的元素
我对使用(JQuery(Ui))拖动多个选定元素的最佳方式感兴趣。
目前我正在使用这段代码,
// Make all divs inside draggableArea draggable
$("#dragableArea div").draggable({
start : function() {
}
drag : function() {
// Calculate position of other selected elements here
// by hand
}
stop : function() {
}
});
我很好奇是否有更好的方法来实现同样的事情? 我想在所有选定的项目上触发拖动事件,以便在拖动其中任何一个项目时它们会自动移动。是否可能,如果可能,如何(至少在理论上)?
I'm interested in best way to achieve dragging multiple selected elements using (JQuery (Ui)).
At the moment I'm using this piece of code
// Make all divs inside draggableArea draggable
$("#dragableArea div").draggable({
start : function() {
}
drag : function() {
// Calculate position of other selected elements here
// by hand
}
stop : function() {
}
});
I'm curious to know if there is some better way to achieve the same thing?
I would like to trigger the drag event on all selected items, so that they automatically move when any of them is dragged. Is it possible and if yes how (at least in theory)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个: http://jsfiddle.net/maniator/zVZFq/5/
基于关于我的回答(和评论):如何使用 JavaScript 或 jQuery 一次拖动多个元素?< /a>
单击以激活多重拖动。
Try this out: http://jsfiddle.net/maniator/zVZFq/5/
Based on my answer (and comments) here: How do I drag multiple elements at once with JavaScript or jQuery?
Click to activate the multi-drag.
这是基于 Neal 解决方案的工作组举措,但可能更具可读性(无论如何对我来说)并带有注释: http: //jsfiddle.net/stevea/CrJbQ/。它的工作原理类似于图形程序的“组”功能。单击要分组的框。这将他们置于“团体飞机”上。通过拖动组平面或任何分组框来移动组平面。单击组平面可取消分组框的分组,将它们保留在新位置。
Here's a working group move based on Neal's solution but perhaps a bit more readable (for me anyway) and with comments: http://jsfiddle.net/stevea/CrJbQ/. It works like a graphic program's "group" function. Click the boxes you want to group. This puts them onto a "group plane." Move the group plane by dragging it or any of the grouped boxes. Click the group plane to ungroup the grouped boxes, leaving them at their new position.