Question:
I'm trying to do a pure Drag'n Drop with Javascript:
Two errors if I'm not able to solve:
1 – When I drag List 2 it always places the element under the mouse and not on top.
2 – When I try to get the element by Class I can't.
Note: By Id he can drag normally.
Answer:
Try this:
In drag init you put it like this:
function drag_init(elem) {
selected = elem;
y_elem = y_pos - selected.closest('ul').offsetTop;
}
And the document.getElementClassName
you replace with:
document.querySelectorAll('.draggable').forEach(function(el) {
el.onmousedown = function () {
drag_init(this);
return false;
};
});
https://jsfiddle.net/8vzj322e/10/