<style>
#move{
width: 200px;
height: 100px;
background: red;
position: absolute;
left: 40%;
top: 40%;
cursor: pointer;
}
</style>
<div id="move">
</div>
<script>
/*
onmouseover
onmouseout 鼠标移开
onmousedown 鼠标按下
onmouseup 鼠标松开
addEvendLister bind
removeEventListener unbind
*/
$("#move").mousedown(function(event){
var spaceX=event.clientX-$(this).offset().left;
var spaceY=event.clientY-$(this).offset().top;
$(document).bind('mousemove',function(event){
var left=event.clientX-spaceX;
var top=event.clientY-spaceY;
$("#move").css({left,top})
})
})
$("#move").mouseup(function(){
$(document).unbind("mousemove")
})
</script>