Change Flex Divs Order with Drag & Drop (No Jquery UI)

I have a group of flex divs which can be drag and drop, and as you can see, when any of them is dropped in any place different to its original place, it come back. Thus far, everything ok. What and trying to do now is that when you drop any div above another div, both changes their respective order. I’m only been able to do this with just one div (in the example, is the number eight), and I tried a lot of things, but i have no idea how extend this behavior to all divs. I’m using this plugin (, and, if its possible, i dont want to use jQuery UI (too weight for what i need). Is it possible make it whit only jQuery? (or some lightweigth plugin, but i search a lot and i dind’n find anyone). Thanks.

<div class="inventory"></div>

.inventory {
    height: 300px;
    width: 400px;
    border: 1px black solid;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;


.item {
    width: 100px;
    height: 100px;
    box-sizing: border-box;
    border: 1px black solid;
    background-color: red;

// external js: draggabilly.pkgd.js

$(document).ready( function() {

    for(var i=1;i<=12;i++) {
        $(".inventory").append('<div class="item"></div>');

    i = 0;

        var n = i.toString();
        $(this).text(n + n);
        var offsetX = $(this).css("left");
        var offsetY = $(this).css("top");

        $(this).css("order", i);

            $(this).css({"transition": "none", "z-index": "9999", "background-color": "red"})

                    $(this).css({"z-index": "1"});

                    var posX = e.pageX;
                    var posY = e.pageY;
                    var offset = $(".8").offset();
                    var right = offset.left + $(".8").width();
                    var bottom = + $(".8").height();
                    var order = $(this).css("order");
                    var order8 = $(".8").css("order");

                    $("p").html("posX: " + posX + " posY: " + posY + " 8 top: " + + " value: " + n);

                    if( bottom > posY 
                    &&  posY > 
                    && right > posX 
                    && posX> offset.left) {

                        $(this).css("order", order8);
                        $(".8").css("order", order);
                        $(this).css("background-color", "grey");

                    else {
                        $(this).css("background-color", "yellow");


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.