87,910
社区成员
发帖
与我相关
我的任务
分享
$(function(){
var dx=0;
var dy=0;
$("#Div2").mousedown(function (event){
event = event || window.event;
$("#Div2").css("cursor","move");
var divOff=$("#Div2").offset();
dx=event.clientX-divOff.left;
dy=event.clientY-divOff.top;
$("#Div2").mousemove(drag(event,dx,dy))
$("#Div2").mouseup(dragEnd())
})
})
function drag(event,dx,dy){
event = event || window.event;
$("#Div2").css("cursor","move");
//$("#Div2").html(event.clientX+" "+dx+" "+event.clientY+" "+dy);
$("#Div1").css("left",(event.clientX-dx))
$("#Div1").css("top",(event.clientY-dy))
}
function dragEnd(){
$("#Div2").css("cursor","")
$("#Div2").unbind("mousemove","drag(event,dx,dy)");
$("#Div2").unbind("mouseup","dragEnd()");
}