<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Author" content="asfman">
</head>
<body>
<script language="javascript">
var dragObject=null,iOffset;
function mousePos()
{
var x,y;
x=event.clientX+document.body.scrollLeft-document.body.clientLeft;
y=event.clientY+document.body.scrollTop-document.body.clientTop;
return {"x":x,"y":y}
}
function getPosition(o)
{
var left=0,top=0,iBorder;
while(o!=document.body)
{
iBorder=parseInt(o.offsetParent.currentStyle.borderWidth);
iBorder=iBorder?iBorder:0;
left+=o.offsetLeft+iBorder;
top+=o.offsetTop+iBorder;
o=o.offsetParent;
}
return {"left":left,"top":top};
}
function mouseOffset(o)
{
var x,y,obj,mPos;
obj=getPosition(o);
mPos=mousePos();
x=mPos.x-obj.left;
y=mPos.y-obj.top;
return {"offsetX":x,"offsetY":y};
}
function makeDrag(o)
{
if(!o)return;
o.onmousedown=function()
{
dragObject=this;
iOffset=mouseOffset(this);
}
}
document.onmousemove=function()
{
if(dragObject)
{
var mPos=mousePos();
dragObject.style.position="absolute";
dragObject.style.left=mPos.x-iOffset.offsetX;
dragObject.style.top=mPos.y-iOffset.offsetY;
return false;
}
}
document.onmouseup=function()
{
if(dragObject)
{
dragObject=null;
setTimeout(CollectGarbage,100);
}
}
window.onload=function()
{
makeDrag(document.getElementById("img1"));
makeDrag(document.getElementById("img2"));
makeDrag(document.getElementById("img3"));
}
</script>
<img src="http://bbs.51js.com/images/default/logo.gif" width=191 height=75 id=img1>
<img src="http://bbs.51js.com/images/default/logo.gif" width=191 height=75 id=img2>
<img src="http://bbs.51js.com/images/default/logo.gif" width=191 height=75 id=img3>
</body>
</html>
posted on 2007-06-01 22:20
汪杰 阅读(191)
评论(0) 编辑 收藏 引用 所属分类:
javascript