i want to be able to create a copy of the element that i want to drag. im using the standard ui draggable and droppable. i know about the helper clone option. but that does not create a copy. the dragged item gets reverted back to the original position.
+6
A:
Mark,
Try this example:
$(document).ready(function(){
$(".objectDrag").draggable({helper:'clone'});
$("#garbageCollector").droppable({
accept: ".objectDrag",
drop: function(event,ui){
console.log("Item was Dropped");
$(this).append($(ui.draggable).clone());
}
});
});
And the Html looks like this
<div class="objectDrag"
style="width:10%; color:white;border:black 1px solid; background-color:#00A">Drag me</div>
<div id="garbageCollector" style="width:100%; height:400px; background-color:#333; color:white;"> Drop items on me</div>
Scott
2009-03-08 16:26:27
Scott,thanks a lot for this.But I want the cloned/dropped element to be in the same position it was dropped. do you know how i can do it? i tried to add .css(ui.position). but it did not work
mark
2009-03-08 19:36:59
Mark, my first guess would've been to use the .css(ui.position), but if you've tried that... What you could try is to create an temp copy of the draggable object on stop. This should contain the relative position of the object. Append that to the container instead of the object itself. Let me know
Scott
2009-03-09 13:33:32
Hell yeah! I found this off of Google and it helped big time. Thanks!
Some Canuck
2009-05-30 16:31:22
Excellent! Neat and simple.
NLV
2010-09-25 09:59:11
A:
This was very helpful, but I can't redrag the original after. Any ideas?
Mark
2009-10-06 15:20:24
A:
Thanks for your solution. But can I know hw it improve to the clone for multiple times? Sadee
Sadee
2009-11-26 04:31:07
A:
I don't know if this will help but with this guys example you can drag and drop the text may times. http://skfox.com/2008/11/26/jquery-example-inserting-text-with-drag-n-drop/
dburmeister
2010-02-01 20:23:40
A:
To redrag the clone/copy use $(this).append($(ui.draggable).clone(true));
parampadam
2010-03-01 13:05:11