jQuery UI从多个Draggable拖放位置
我有一个可投放容器,其中包含> 1个可拖动对象.我只希望每次拖动任何可拖动对象的位置时都能看到它们的位置.听起来很简单,但是我很难解决这个问题.这就是我所拥有的:
I have a droppable container with >1 draggables in it. I want to simply be able to see the position of each draggable every time any one of them is dragged. Sounds easy, but I'm having a tough time figuring it out. Here's what I have:
<script type="text/javascript">
$(function() {
$("#draggable").draggable({ containment: '#droppable' });
$("#draggable2").draggable({ containment: '#droppable' });
$("#droppable").droppable({
drop: function(event, ui) {
document.getElementById('position1').value = ui.position.top + ', ' + ui.position.left;
}
});
});
</script>
基本上,在我有position1输入id收集位置的情况下,我想让第二行对其他可拖动对象执行相同的操作.
Basically, where I have the position1 input id gathering the position, I want to have a second line do the same thing for the other draggable.
在您的情况下,您无需使用ui
参数.由于您知道可拖动的元素,因此可以专门选择它们并找到它们的位置.另外,由于您使用的是jQuery,请帮自己一个忙,将document.getElementById
替换为$
. :-)
In your case, you don't need to use the ui
parameter. Since you know what elements are draggable, you can select them specifically and find their positions. Also, since you're using jQuery, do yourself a favor and replace document.getElementById
with $
. :-)