asp.net中鼠標移動圖片
2008-01-09 15:41
246 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<html>
<head>
<title>Test</title>
<script language="javascript">
var ox,oy,ex,ey;
var stepx,stepy,TimeSpan=20;
var ts=null;
document.onclick=Handler;
var MoveObj=null;
window.onload=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>
<html>
<head>
<title>Test</title>
<script language="javascript">
var ox,oy,ex,ey;
var stepx,stepy,TimeSpan=20;
var ts=null;
document.onclick=Handler;
var MoveObj=null;
window.onload=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>
相关文章推荐
- (原創) 如何將圖片上下翻轉? (.NET) (ASP.NET) (GDI+) (Image Processing)
- asp.net 圖片上傳方法/匯總/縮放截取
- [asp.net] xheditor 圖片上傳 功能
- asp.net下載往上圖片
- asp.net為圖片加上水印
- ASP.NET 在域控制器上使用默认 ASPNET 帐户不能正常运行!
- ASP.NET程序中常用代码汇总(三)
- 在ASP.NET中实现Url Rewriting
- (MSDN精选)IIS 5.0 和 6.0 的 ASP.NET 应用程序生命周期概述
- 分享关于ASP.NET中等安全模式的一些经验
- FCKEditor 2.6.4 Asp.net上传文件没有权限解决
- 了解 ASP.NET AJAX 验证和配置文件应用程序服务(三)
- c# asp .net 动态创建sql数据库表
- ASP.Net中的四种状态保持机制
- Click Button to Export Excel Asp.net C#
- SEND E-MAIL ASP.NET 发送E-Mail的代码
- ASP.NET Core的路由[3]:Router的创建者——RouteBuilder
- asp.net mvc当出现错误时如何实现友好错误提示
- 开发设计模式 -- Asp.net中实现观察者模式
- 在ASP.NET WEB控件中应用样式(Style)