Jquery UI Draggable Absolute Instead of Relative?

VolatileStorm picture VolatileStorm · Aug 1, 2011 · Viewed 26.6k times · Source

I have a div containing a few jquery draggables, however if at any point I remove one of these draggables from the page then this can move the rest of them as they are positioned with relative.

Here is a fiddle showcasing this: http://jsfiddle.net/VolatileStorm/aNk6e/

My proposed solution is that the draggable should be using absolute as opposed to relative positioning, however I can't find a way to do this. Is there a way to do this, and if not, can anyone think of a way around it? (For elegance's sake, I won't accept "don't delete the other draggable").

Answer

Paul Draper picture Paul Draper · Mar 16, 2014
  1. Add position:absolute to your elements.
  2. Attach them to the DOM before calling .draggable.