I played with the jQuery UI draggable and struggled with maintaining the position of an element while dragging an element from one parent to another. As soon as the element is moved to another parent, its positioning goes away. Then I continued with the offset training and applied it to the element, and it worked very well until I started styling the page, and then it was even worse than before.
This seems like a simple requirement, so not sure if I miss the obvious trick?
Sorry if the above is not clear, it is rather difficult to explain.
Thanks Steve
ps. just the js code below, it is not very good and some of the values that I have hard-coded now:
$(document).ready(function() {
makeDraggable($(".draggable"));
});
function makeDraggable(el) {
var clone ;
var x = 0;
var y = 0;
$(el).draggable({
zIndex: 1000,
start:function() {
if($(this).parent().parent().attr("id") == "browser") {
clone = $(this).clone();
makeDraggable($(clone));
$(clone).css("position","absolute");
$(clone).css("z-index","0");
$(this).parent().append($(clone));
}
},
drag:function() {},
stop:function() {
if($(this).parent().parent().attr("id") == "browser") {
var offset = 0;
var total_item_width = parseInt($(this).css("padding-left"))+parseInt($(this).css("padding-right"))+$(this).width();
$(clone).css("position","relative");
$("#canvas").append($(this));
offset = ($("#canvas").find(".draggable").size()-1)*total_item_width;
$(this).css("left",parseInt($(this).css("left"))+827-offset);
offset = ($("#canvas").find(".draggable").size()-1)*($(this).height()+12);
$(this).css("top",parseInt($(this).position().top));
}
}
});
}
source
share