<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
div{
width:100px;
height:100px;
background-color:aquamarine;
}
</style>
</head>
<body>
<div></div>
<script>
let div = document.querySelector("div")
div.style.position = "absolute"
w = parseInt(getComputedStyle(div).width)
h = parseInt(getComputedStyle(div).height)
div.onmousedown = function () {
div.onmousemove = function (ev) {
div.style.left = (ev.pageX - w / 2) + "px"
div.style.top = (ev.pageY - h / 2) + "px"
}
}
div.onmouseup = function () {
div.onmousemove = null
}
</script>
</body>
</html>