I am working on a tool based on jQuery UI draggable functionality.
I have a number of boxes in the left column of the table. When they are dragged in yellow area, I would expect the remaining divs to move upwards to fill the space left by the box that was moved.
But it’s not happening. Why?
It is pretty difficult to test but from my knowledge on the question here is a possible cause/solution to this.
The
droppableplugin does not remove the dragged element from its original markup position, it is visually moved to the droppable element (with some option allowing to accept to drop certain elements or not, events, etc).The elements have a
position: relativecss rule, which represents the “normal flow” for elements (in the order they appear in the markup). So even if the element is visually placed elsewhere on the page with css, its place in the markup is still the same and it is still taking the space it normally should.This fiddle illustrate what i’m trying to explain 🙂
By looking at the source code form the “working website”, they actually remove the dragged element from the original draggable list and re-create it in the droppable list !
When they define the
.droppable()they do this:On the
dropevent, they callputCardIntoStack(card, c)passing the currently dragged element as thecardparameter. Within this method, they remove the original “card” (a.remove()) and re-create it in the dropzone (newcard = createCard();):jQuery UI does a similar thing on the droppable demo page. On the
dropevent, they call a functiondeleteImage()which removes the dragged image from the original markup and appends it to the drop zone.I hope I’m clear enough 🙂
I also hope I’m right, it is pretty difficult to test quickly but it makes sense 🙂