Question: Motivation for cloning "originalSource"
When an element gets dragged, a clone of the element is created and also the original element will get hidden. Just curious about the motivation for such a behavior π
(For my specific use case... this behavior a bit undesirable, but not really a major issue)
@stkao05 what is the exact behaviour that you need?
As of the latest pushes to master, we have made it so the mirror has been abstracted a bit more. You can now initialize draggable without any mirror.
As for cloning behaviour - the reason why we have a source vs originalSource is because of what happens with touch events. Since draggable items are being moved around in the DOM as you drag, that means the original element that you have initiated the event on has been changed in some way (example: removed and reappended to the dom). This just won't fly sadly - so:
- on
drag:start, hide theoriginalSourceand leave it in place in the DOM - duplicate the
originalSourceassourceand append it next tooriginalSource - now start moving this new
sourcearound in the DOM- changes happen to
sourcewhileoriginalSourcecan retain the originaleventListener
- changes happen to
- on
drag:stop, remove the clonedsourceand replace it with theoriginalSource
Does that make sense? Please let me know if you need more clarity.
@tsov in case you have a better description.
Thanks for the detail explanation @beefchimi πGlad to see the library is still in active development.
Sorry, I am still trying to wrap my head around it. Yes, the original draggable item could be changed in some way during the drag-and-drop process, but I wasn't sure why would that be an issue?
^ @tsov was there anything you wanted to add here?
@beefchimi you got it π
We should really file an issue about this, this always sounded like a browser bug to me!
Would there be a side-effect to removing the style attributes which hides the original? The reason I want it is that I want to display the original until I drop the element to its new position. Or is there a more idiomatic way of achieving this?
Would there be a side-effect to removing the style attributes which hides the original? The reason I want it is that I want to display the original until I drop the element to its new position. Or is there a more idiomatic way of achieving this?
Hi @miralize , If removing the display: none of the originalSource, it will also act as a draggable element and move over it will trigger drag:over.
It seems that clone an originalSource again and remove the draggable class of it can avoid treating it as a draggable element.