<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#a{
width: 100px;
height: 100px;
background: yellow;
position: absolute;
}
</style>
</head>
<body>
<div id='a'></div>
<script type="text/javascript">
a.onmousedown=function(e){
var ev=e||event
var l=ev.clientX -this.offsetLeft;
var t=ev.clientY -this.offsetTop;
document.onmousemove=function(e){
var ev=e||event
a.style.left=ev.clientX-l+'px';
a.style.top=ev.clientY-t+'px'
};
document.onmouseup=function(){
document.onmousemove=null;
document.onmousedown=null;
}
return false;
}
</script>
</body>
</html>