let div=document.getElementById("dsa")
let diffx=0,diffy=0,falg=false;
div.onmousedown=function(e){
diffx=e.offsetX;
diffy=e.offsetY;
flag=true;
}
div.onmousemove=function(e){
if(flag){
div.style.marginLeft=(e.clientX-diffx)+"px";
div.style.marginTop=(e.clientY-diffy)+"px";
}
}
div.onmouseup=function(){
flag=false;
}
<div id="dsa"></div>
div{
height:100px;
width:100px;
background:green;
}