<html>
<head>
<style type='text/css'>
#div1{width:100px;height:100px;background:red;position:absolute;}
</style>
<script>
window.onload=function(){
var oDiv = document.getElementById("div1");
oDiv.onmousedown=function(ev){
var oEvent = ev||event;
var disX = oEvent.clientX-oEvent.offsetLeft;
var disY = oEvent.clientY - oEvent.offsetTop;
document.onmousemove=function(ev){
var oEvent = ev||event;
oDiv.style.left=oEvent.clientX-disX+"px";
oDiv.style.top=oEvent.clientY-disY+"px";
}
document.onmouseUp=function(ev){
document.onmousemove=null;
document.onmouseUp=null;
}
}
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>