In the stop
callback, you can use ui.helper
to access the item being dragged. Then use offset
on it, as Brad suggested:
$("#image").draggable({ stop:function(event,ui) { var wrapper = $("#wrapper").offset(); var borderLeft = parseInt($("#wrapper").css("border-left-width"),10); var borderTop = parseInt($("#wrapper").css("border-top-width"),10); var pos = ui.helper.offset(); $("#source_x").val(pos.left - wrapper.left - borderLeft); $("#source_y").val(pos.top - wrapper.top - borderTop); alert($("#source_x").val() + "," + $("#source_y").val()); } });
Then you just need to configure it for your packaging - subtract its offset and the width of its border - and set it to your input val
. (sorry for hard coding the border, but I could not extract it using css
) (Edit: there he found a solution in another question )
http://jsfiddle.net/mgibsonbr/naqbq/4/
source share