jQuery UI从多个Draggable拖放位置 [英] jquery ui drag/drop getting position from multiple draggables

查看:255
本文介绍了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 $. :-)

这篇关于jQuery UI从多个Draggable拖放位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆