asp.net點擊鼠標移動圖片

<html>
<head>
<title>Test</title>
<script language="javascript">
var ox,oy,ex,ey;
var stepx,stepy,TimeSpan=20;
var ts=null;
document.οnclick=Handler;
var MoveObj=null;
window.οnlοad=function()
{
  MoveObj=document.getElementById("pic");
}
function Handler(e)
{
  clearInterval(ts);//
  e=e||event;
  alert(e);
  var pic=document.getElementById("pic");
  ox=parseInt(pic.style.left);
  oy=parseInt(pic.style.top);
  ex=e.clientX;
  ey=e.clientY;
  if(ex>ox)
  {
    stepx=1;
  }
  else
  {
    stepx=-1;
  }
  stepy=(ey-oy)/(ex-ox);//根据比例算出y方向的移动速度
  ts=setInterval("movePic()",TimeSpan);
}
function movePic()
{    
   ox+=stepx;
   oy+=stepy;
   if(stepx>0)
   {    
     if(ox<=ex)
       MoveObj.style.left=ox+"px";
     else
       MoveObj.style.left=ex+"px";
   }
   else
   {
     if(ox>=ex)
       MoveObj.style.left=ox+"px";
     else
       MoveObj.style.left=ex+"px";
   }
   if(stepy>0)
   {    
     if(oy<=ey)
       MoveObj.style.top=oy+"px";
     else
       MoveObj.style.top=ey+"px";
   }
   else
   {
     if(oy>=ey)
       MoveObj.style.top=oy+"px";
     else
       MoveObj.style.top=ey+"px";
   }
   if(parseFloat(MoveObj.style.top)==parseInt(ey)&&parseFloat(MoveObj.style.left)==parseInt(ex))
     clearInterval(ts);
}
</script>
</head>
<body>
<img src="images/toqq.gif" id="pic" style='position:absolute;left:0px;top:0px;width:120px;height:100px'/>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值