<script language="JavaScript">
var allow=false;//判断是否允许被拖动
var img;//被拖动的图片的对象
var x;//鼠标相对于浏览器的x坐标
var y;//鼠标相对于浏览器y坐标
function move()
{
if (event.button==1 && allow) //改变被拖动元素在页面上的位置
{
img.style.pixelLeft=temp1+event.clientX-x;
img.style.pixelTop=temp2+event.clientY-y;
}
}
function begin()
{
if (!document.all)//说明一个元素也没有则结束
return
if (event.srcElement.id=="drag") //捕捉鼠标和被拖动元素的当前位置,通过id来获得某个唯一元素
{
allow=true;
img=event.srcElement;
temp1=img.style.pixelLeft;//记录该图片的x坐标
temp2=img.style.pixelTop;
x=event.clientX;//记录鼠标当前的x坐标
y=event.clientY;
document.onmousemove=move;
}
}
document.onmousedown=begin; //鼠标左键按下时,准备拖动
document.onmouseup=function(){allow=false}//鼠标左键放开时,拖动停止
</script>
<span style="font-family:DextorOutD;font-size: 9pt"><img src="**********.jpg" id="drag" onmouseover="this.style.cursor='hand';this.style.position='relative'"></span>
var allow=false;//判断是否允许被拖动
var img;//被拖动的图片的对象
var x;//鼠标相对于浏览器的x坐标
var y;//鼠标相对于浏览器y坐标
function move()
{
if (event.button==1 && allow) //改变被拖动元素在页面上的位置
{
img.style.pixelLeft=temp1+event.clientX-x;
img.style.pixelTop=temp2+event.clientY-y;
}
}
function begin()
{
if (!document.all)//说明一个元素也没有则结束
return
if (event.srcElement.id=="drag") //捕捉鼠标和被拖动元素的当前位置,通过id来获得某个唯一元素
{
allow=true;
img=event.srcElement;
temp1=img.style.pixelLeft;//记录该图片的x坐标
temp2=img.style.pixelTop;
x=event.clientX;//记录鼠标当前的x坐标
y=event.clientY;
document.onmousemove=move;
}
}
document.onmousedown=begin; //鼠标左键按下时,准备拖动
document.onmouseup=function(){allow=false}//鼠标左键放开时,拖动停止
</script>
<span style="font-family:DextorOutD;font-size: 9pt"><img src="**********.jpg" id="drag" onmouseover="this.style.cursor='hand';this.style.position='relative'"></span>