87,919
社区成员
发帖
与我相关
我的任务
分享
<script>
/**
**@author lonephoenix
**/
var Drag=function(obj) {
var x,y,ox,oy;
var nx,ny;
var objmove=new Boolean(false);
obj.onmousedown=function(e) {
e=e||event;
if(e.button==0) {
obj.style.cursor="move";
ox=obj.offsetLeft;
oy=obj.offsetTop;
x=e.clientX;
y=e.clientY;
objmove=true;
};
};
obj.onmousemove=function(e) {
e=e||event;
if(objmove==true) {
nx=ox+e.clientX-x;
ny=oy+e.clientY-y;
obj.style.left=nx+"px";
obj.style.top=ny+"px";
}
};
obj.onmouseup=function(e) {
e=e||event;
if(e.button==0) {
objmove=false;
obj.style.cursor="default";
}
};
};
window.onload=function() {
var oDiv=document.getElementsByTagName("div")[0];
Drag(oDiv);
}