简体   繁体   English

jQuery UI从多个Draggable拖放位置

[英]jquery ui drag/drop getting position from multiple draggables

I have a droppable container with >1 draggables in it. 我有一个可投放容器,其中> 1个可拖动对象。 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>

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. 基本上,在我有position1输入id收集位置的地方,我想让第二行对其他可拖动对象执行相同的操作。

In your case, you don't need to use the ui parameter. 在您的情况下,您不需要使用ui参数。 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 $ . 另外,由于您使用的是jQuery,请帮自己一个忙,并用$替换document.getElementById :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM