日期:2014-05-17  浏览次数:20561 次

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

                   
                                                                网页飞行图片*{font-size:12px;color:;}a{text-decoration:none;}a:hover{color:red;}//原作:风云舞,载自:http://www.lshdic.com/bbsvar 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.innerHTML=str1; //插入STR1,STR1是5个VML球的代码function play1(){ //播放函数wid1=a.offsetWidth;hei1=a.offsetHeightif(wid1-xxif(xxif(hei1-yyif(yyif (xjia==true)xx+=5;else xx-=5 //TRUE的话就++,FALSE的话就--if (yjia==true)yy+=5;else yy-=5img1.style.left=xx;img1.style.top=yy //更新球的位置}setInterval("play1()",10) //10毫秒播放一次,一般CPU保证能消化~~~ 经典的算法