JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test"></div>
<div id="out">bla</div>
CSS
#test{
width:40px;
height:40px;
background-color:#000;
position:absolute;
}
JavaScript
var div = document.getElementById('test');
var out = document.getElementById('out');
var mouseDown = false;
window.onmousemove = function(e){
if(mouseDown == true){
out.innerHtml = parseInt(div.style.top, 10);
div.style.top = (e.pageY-parseInt(div.style.top, 10))+'px';
div.style.left = (e.pageX-parseInt(div.style.left, 10))+'px';
}
};
div.onmousedown = function(){
mouseDown = true;
};
window.onmouseup = function(){
mouseDown = false;
};