Drag n Drop pure Javascript

3

I'm trying to make a pure Drag'n Drop with Javascript:

Example

Two errors if I can not solve:

1 - When dragging List 2 it always places the element under the mouse and not above.

2 - When I try to get the element through Class I can not.

Obs: By Id it can drag normally.

    
asked by anonymous 25.11.2016 / 18:26

1 answer

3

Try this:

No drag init puts you like this:

function drag_init(elem) {    
    selected = elem;    
    y_elem = y_pos - selected.closest('ul').offsetTop;
}

And document.getElementClassName you replace with:

document.querySelectorAll('.draggable').forEach(function(el) {
    el.onmousedown = function () { 
        drag_init(this);
        return false;
    };
});

link

    
25.11.2016 / 18:47