我一般是把图片放层里一起拖动,昨天写了一个集各家之长的(其实就是拼凑的)带拖动控制的脚本...
var ie=document.all?true:false
var mouseX=0,mouseY=0,tempX=0,tempY=0
var objid,obj='';
function dragStart(objid)//onMouseDown
{
obj=objid;
document.getElementById(obj).setCapture();
tempX=event.x-document.getElementById(obj).offsetLeft;
tempY=event.y-document.getElementById(obj).offsetTop;
}
function layermove()//onMouseMove
{
if (obj!='')
{
if (ie)
{
mouseX=event.clientX;
mouseY=event.clientY;
}
else
{
alert("请在IE中打开本页面")
}
var tempW=parseInt(document.getElementById(obj).style.width);
if (mouseX-tempX<=0)
{
mouseX=tempX;
}
if (mouseY-tempY<=0)
{
mouseY=tempY;
}
if (mouseX-tempX+tempW>=1000)
{
mouseX=1000-tempW+tempX;
}
document.getElementById(obj).style.left=mouseX-tempX;
document.getElementById(obj).style.top=mouseY-tempY;
}
}
function dragEnd()//onMouseUp
{
if (obj!='')
{
document.getElementById(obj).releaseCapture();
if (parseInt(document.getElementById(obj).style.left)<0)
{
document.getElementById(obj).style.left=0;
}
if (parseInt(document.getElementById(obj).style.top)<0)
{
document.getElementById(obj).style.top=0;
}
obj='';
}
}