JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.jsdelivr.net/npm/leader-line@1.0.5/leader-line.min.js"></script>
<body>
<button onclick="recalculate()">Recalculate</button>
<div class="editor">
<div id="arrow-container" class="editor-area">
<div id="node1" class="node-host">
<p>
some content here
</p>
</div>
<div id="node2" class="node-host">
<p>
also some content here
</p>
</div>
</div>
</div>
</body>
CSS
html {
height: 80%;
}
body {
height: 100%;
overflow-y: hidden;
overflow-x: hidden;
}
.editor-area {
position: relative;
height: 1000px;
width: 1000px;
}
.editor {
width: 100%;
height: 100%;
overflow-y: scroll;
overflow-x: scroll;
}
.node-host {
width: 100px;
border: solid 1px #ccc;
color: rgba(0, 0, 0, 0.87);
background: #fff;
position: absolute;
border-radius: 4px;
z-index: 10;
transition: box-shadow 200ms cubic-bezier(0, 0, 0.2, 1);
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
0 2px 2px 0 rgba(0, 0, 0, 0.14),
0 1px 5px 0 rgba(0, 0, 0, 0.12);
}
/* element got dragged to this position */
#node1 {
transform: translate3d(40px, 55px, 0px);
}
/* element got dragged to this position */
#node2 {
transform: translate3d(255px, 135px, 0px);
}
JavaScript
var line = new LeaderLine(
document.getElementById('node1'),
document.getElementById('node2')
);
document.getElementById('arrow-container').appendChild(document.querySelector('.leader-line'));
function recalculate() {
line.position();
}