Search code examples
javascriptcssjsplumb

Forming a closed loop of two divs with JsPlumb library


I have 2 divs with position absolute:

<div class="node" id="block1" style="position: absolute;">Block1</div>
<div class="node" id="block2" style="position: absolute;">Block2</div>

Each block has source and target endpoints:

var targetOption = {anchor:"TopCenter",
                    maxConnections:-1, 
                    isSource:false, 
                    isTarget:true, 
                    endpoint:["Dot", {radius:5}], 
                    paintStyle:{fillStyle:"#66FF00"},
                    setDragAllowedWhenFull:true}

var sourceOption = {anchor:"BottomCenter",
                    maxConnections:-1, 
                    isSource:true, 
                    isTarget:false, 
                    endpoint:["Dot", {radius:5}], 
                    paintStyle:{fillStyle:"#FFEF00"},
                    setDragAllowedWhenFull:true}

jsPlumb.bind("ready", function() {

    jsPlumb.addEndpoint('block1', targetOption);
    jsPlumb.addEndpoint('block1', sourceOption);

    jsPlumb.addEndpoint('block2', targetOption);
    jsPlumb.addEndpoint('block2', sourceOption);

    jsPlumb.draggable('block1');
    jsPlumb.draggable('block2');
});

I want to link the source endpoint of each block to the target endpoint of another block, but I can't do it. If I link the source endpoint of the first block to the target endpoint of the second block, the source endpoint of the second block will not work.

Does anyone know where I could be mistaken?


Solution

  • I found the solution. I just need to correctly set the z-index for each object:

    ._jsPlumb_connector {
        z-index:1;
    }
    
    div.node { 
        z-index:2;
    }
    
    ._jsPlumb_endpoint {
        z-index:3;
    }