Dhtml+Js算法:小球运动简化版,变通实现更简单的飞行的图片

lshdic 2003-08-21 02:40:11
<HTML>
<HEAD>
<META http-equiv='Content-Type' content='text/html;charset=gb2312'>
<Meta name='Gemeratpr' content='网络程序员伴侣(Lshdic)2004'>
<TITLE>网页飞行图片</TITLE>
<STYLE>
*{font-size:12px;color:;}
a{text-decoration:none;}
a:hover{color:red;}
</STYLE>
</HEAD>
<BODY topmargin='2' leftmargin='2'>
<BASE target='_top'>
<div id=a style='table-Layout:fixed;width:100%;height:100%;border:1 solid black'></div>
<script>
//原作:风云舞,载自:http://www.lshdic.com/bbs
var wid1,hei1,str1="",xx=0,yy=0,xjia=true,yjia=true //定义全局变量,为提高运行速度
wid1=a.offsetWidth-70;hei1=a.offsetHeight-70 //得到容器的宽和高
//首次向容器内塞进1个飞行的图片,图片位置属性是随机的
tempx=Math.round(Math.random()*wid1);tempy=Math.round(Math.random()*hei1);
str1+="<a href='http://www.lshdic.com/bbs' target='_blank'><img src='http://www.lshdic.com/bbs/image/user30.gif' style='position:absolute;left:"+tempx+";top:"+tempy+";z-index:10;width:150;height:150;' id='img1' border=0></a>"
a.innerHTML=str1; //插入STR1,STR1是5个VML球的代码
function play1(){ //播放函数
wid1=a.offsetWidth;hei1=a.offsetHeight
if(wid1-xx<155)xjia=false //到达X极限,值为FALSE
if(xx<5)xjia=true //到达X起点,值为TRUE
if(hei1-yy<155)yjia=false
if(yy<5)yjia=true
if (xjia==true)xx+=5;else xx-=5 //TRUE的话就++,FALSE的话就--
if (yjia==true)yy+=5;else yy-=5
img1.style.left=xx;img1.style.top=yy //更新球的位置
}
setInterval("play1()",10) //10毫秒播放一次,一般CPU保证能消化~~~
</script>
</BODY>
</HTML>
...全文
36 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧