Skip to content

Resetting positions if drop was not in a designated drop zone #180

Answered by jaks19
jaks19 asked this question in Q&A
Discussion options

You must be logged in to vote

If anyone is interested, here is a sketch of what I did:

  • record positions of html elements when drag starts
  • when drag stops, if in drop zone, process elements
  • when drag stops, if elsewhere, reset element positions to cached original positions

var ds;
var draggedItems;
var droppedItems;

ds = new DragSelect({
        selectables: document.querySelectorAll('.item'),
        dropZones: [{
            id: 'trash',
            element: document.querySelector('#trash-zone')
        }],
            useTransform: false
    });
  
ds.subscribe('dragmove', ({ items, event, isDragging, isDraggingKeyboard }) => {
    draggedItems = items;
});
  
ds.subscribe('callback', ({ dropTarget, isDragging, …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ThibaultJanBeyer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant