简体   繁体   English

jqueryui拖动元素多次

[英]jqueryui drag element multiple times

how can set up drag and drop to allow dragging of one element multiple times 如何设置拖放以允许多次拖动一个元素

i have made something like this http://jsfiddle.net/28SMv/3/ but after draging an item from red to blue the element loses its "draggability" and i cant drag it once more and more. 我已经做了类似http://jsfiddle.net/28SMv/3/的操作,但是在将项目从红色拖动到蓝色后,该元素失去了“可拖动性”,并且我无法一次又一次地拖动它。

adding revert:true to draggable seems to work but then i need to remove helper:'clone' cant use them at the same time 将revert:true添加到draggable似乎可以工作,但是然后我需要删除帮助器:“ clone”不能同时使用它们

You're duplicating/cloning your elements, so the new one obviously won't be draggable. 您正在复制/克隆元素,因此新元素显然不会被拖动。 You could make it draggable, although that's much too much work. 您可以使其可拖动,尽管这需要太多工作。 Just move the original via .append() . 只需通过.append()移动原始文件即可。 Note that when you append an existing object to another element, it will remove the original from its place. 请注意,当您将现有对象附加到另一个元素时,它将从其位置删除原始对象。 That seems to me like what you want to do. 在我看来,这就像您想做什么。

Example: http://jsfiddle.net/28SMv/7/ 示例: http//jsfiddle.net/28SMv/7/

You might want the items to be transferable back into the original div: http://jsfiddle.net/28SMv/8/ 您可能希望这些项目可以转移回原始div: http : //jsfiddle.net/28SMv/8/

Note that I'm using jQuery 1.4.4 there, when you switch over to 1.5 it doesn't work. 请注意,我在那里使用jQuery 1.4.4,当您切换到1.5时它不起作用。 Not sure if that's a bug, or a feature of jQuery. 不知道这是错误还是jQuery的功能。 My guess is that it's a bug of 1.5. 我的猜测是它的错误是1.5。

If you drag an item & release without dropping, it stops being draggable. 如果您拖动某个项目并放开而不放开,则该项目将不再可拖动。 I'd remove all droppable stuff from that jsfiddle example, just put a bunch of draggables on the screen & try with that. 我将从jsfiddle示例中删除所有可放下的东西,只需将一堆可拖动对象放到屏幕上并尝试使用。

One possible solution is to rebind draggables after you're done dragging. 一种可行的解决方案是在完成拖动后重新绑定可拖动对象。 Think: 认为:

function rebindDraggables() {
    $('...').draggable({
        ...
        stop: function() {
            rebindDraggables();
        }
    })
}

I'm not sure why in your examples draggables cease to be draggable after the first time. 我不确定为什么在您的示例中,可拖动对象在第一次之后就不再可拖动了。 The jQuery docs might explain this. jQuery文档可能会对此进行解释。

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

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