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

王朝html/css/js·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

<!--图片下载需用时,请少等片刻即看到效果-->

<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?个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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航