JSFiddle - React, Tailwind, and code Playground
HTML
<div id="div1"></div>
CSS
#div1 {
width: 100px;
height: 100px;
background: red;
position: absolute;
}
JavaScript
window.onload = function() {
var oDiv = document.getElementById('div1');
oDiv.onmousedown = function(ev) {
var ev = ev || event;
var disX = ev.clientX - this.offsetLeft;
var disY = ev.clientY - this.offsetTop;
document.onmousemove = function(ev) {
var ev = ev || event;
oDiv.style.left = ev.clientX - disX + 'px';
oDiv.style.top = ev.clientY - disY + 'px';
}
document.onmouseup = function() {
document.onmousemove = document.onmouseup = null;
}
return false;
}
}