Skip to content Skip to sidebar Skip to footer

Html5 Dragend Event Firing Immediately

I have several draggable elements
Box 1: Milk was a bad choice.
Box

Solution 1:

As i mentioned in the topic dragend, dragenter, and dragleave firing off immediately when I drag , what solved the problem (which looks to be a Chrome bug) for me was to add a setTimeout of 10 milliseconds into the handler and manipulate the DOM in that timeout.

Solution 2:

I don't have a direct solution, but changing the DOM in the dragStart event handler is causing this problem, and any code that changes the DOM should really go in the dragEnter event handler - doing so, drag&drop events are fired more reliably.

Not sure whether this is by design - it feels a bit like a bug though.

Solution 3:

This is a known chrome issue. Problem is, as Joerg mentions that you manipulates the dom on dragstart.

You can do so, but you need to do it in a timeout.

Solution 4:

Just had the same problem. I was manipulating the DOM by changing an elements position to fixed in dragStart. I fixed my issues using Ivan's answer like this:

/* This function produced the issue */functiondragStart(ev) {
    /* some code */
    myElement.style.position="fixed";
}

/* This function corrected issue */functiondragStart(ev) {
    /*some code */setTimeout(functionchangePos() {
        myElement.style.position="fixed";
        }, 10);
}

It seems like the answer to your problem would be

function startDrag(e){
  console.log('dragging...');
  setTimeout(addDropSpaces(),10);
  e.stopPropagation();
}

Post a Comment for "Html5 Dragend Event Firing Immediately"