<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#d1{
width: 250px;
height: 250px;
background-color: red;
position: absolute;
cursor: move;
}
</style>
</head>
<body>
<div id="d1"></div>
<script type="text/javascript">
var d1Node = document.getElementById("d1");
d1Node.onmousedown = function(e){
var w = e.clientX - d1Node.offsetLeft;
var h = e.clientY - d1Node.offsetTop;
document.onmousemove = function(ev){
d1Node.style.top = (ev.clientY - h) + "px";
d1Node.style.left = (ev.clientX - w)+ "px";
}
}
d1Node.onmouseup = function(){
document.onmousemove = null;
}
</script>
</body>
</html>