2008年8月29日

卫星围绕鼠标

代码效果:卫星围绕鼠标。

代码如下:

<!--将以下代码加入HTML的<Body></Body>之间--><br /><SCRIPT language=JavaScript><br /><!-- <br />Clrs=new Array('ff0000','00ff00','ffffff','ff00ff','ffa500','ffff00','00ff00','ffffff','ff00ff')<br />var speed=1;<br />var RunTime = 0;<br />var cntr=0;<br />var xcntr=100;<br />var Nslayers;<br />var pulse=25;<br />var onClrs;<br />var Xpos = 421;<br />var Ypos = 231;<br />var _y;<br />if (document.layers){<br />window.captureEvents(Event.MOUSEMOVE);<br />function xFollowMouse(evnt){<br />Xpos = evnt.pageX;<br />Ypos = evnt.pageY;<br />}<br />window.onMouseMove = xFollowMouse;<br />document.write('<layer name="a0" left=10 top=10 bgcolor="#ff0000" clip="0,0,2,2"></layer>'<br />+'<layer name="a1" left=10 top=10 bgcolor="#00ff00" clip="0,0,2,2"></layer>'<br />+'<layer name="a2" left=10 top=10 bgcolor="#ffffff" clip="0,0,2,2"></layer>'<br />+'<layer name="a3" left=10 top=10 bgcolor="#ffa500" clip="0,0,2,2"></layer>'<br />+'<layer name="a4" left=10 top=10 bgcolor="#ff00ff" clip="0,0,2,2"></layer>'<br />+'<layer name="a5" left=10 top=10 bgcolor="#8888ff" clip="0,0,2,2"></layer>'<br />+'<layer name="a6" left=10 top=10 bgcolor="#fff000" clip="0,0,2,2"></layer>');<br />}<br />else if (document.all){<br />function FollowMouse(){<br />Xpos = document.body.scrollLeft+event.x;<br />Ypos = document.body.scrollTop+event.y;<br />}<br />document.onmousemove = FollowMouse;<br />document.write('<div id="ieDiv" style="position:absolute;top:0px;left:0px">'<br />+'<div id="c" style="position:relative">'<br />+'<div style="position:absolute;top:0px;left:0px;width:2px;height:2px;background:#ff0000;font-size:2px"></div>'<br />+'<div style="position:absolute;top:0px;left:0px;width:2px;height:2px;background:#00ff00;font-size:2px"></div>'<br />+'<div style="position:absolute;top:0px;left:0px;width:2px;height:2px;background:#ffffff;font-size:2px"></div>'<br />+'<div style="position:absolute;top:0px;left:0px;width:2px;height:2px;background:#ffa500;font-size:2px"></div>'<br />+'<div style="position:absolute;top:0px;left:0px;width:2px;height:2px;background:#ff00ff;font-size:2px"></div>'<br />+'<div style="position:absolute;top:0px;left:0px;width:2px;height:2px;background:#8888ff;font-size:2px"></div>'<br />+'<div style="position:absolute;top:0px;left:0px;width:2px;height:2px;background:#fff000;font-size:2px"></div>'<br />+'</div>'<br />+'</div>');<br />}<br />function sv2(){<br />if (document.layers){<br />for (i=0;i<7;i++)<br />{<br />Nslayers="a"+i;<br />document.layers[0].top=Ypos+cntr*Math.cos((RunTime+i*4.5)/5);<br />document.layers[0].left=Xpos+cntr*Math.sin((RunTime+i*4.5)/5);<br />var randCol=Math.round(Math.random()*8);<br />document.layers[0].bgColor=Clrs[randCol]; <br />}<br />cntr+=1;<br />RunTime+=speed;<br />stp=setTimeout('sv2()',10);<br />if (cntr>=100)<br />{<br />cntr=100;<br />speed=2.5;<br />for (i=0;i<7;i++)<br /> {<br /> Nslayers="a"+i;<br /> document.layers[Nslayers].top=Ypos+cntr*Math.cos((RunTime-100)*i/90);<br /> document.layers[Nslayers].left=Xpos+cntr*Math.sin((RunTime-100)*i/90);<br /> }<br />}<br />if (RunTime>182)<br />{<br />speed=0.5;<br />for (i=0;i<7;i++)<br /> {<br /> Nslayers="a"+i;<br /> document.layers[Nslayers].top=Ypos+xcntr*Math.cos(((RunTime-182)+i*4.5)/5)*Math.cos((RunTime-182)/5);<br /> document.layers[Nslayers].left=Xpos+xcntr*Math.sin(((RunTime-182)+i*4.5)/5);<br /> }<br />}<br />}<br />else if (document.all){<br />for (i=0;i<ieDiv.all.c.all.length;i++)<br />{<br />var randCol=Math.round(Math.random()*8);<br />ieDiv.all.c.all[0].style.background=Clrs[randCol];<br />ieDiv.all.c.all[0].style.top=Ypos+cntr*Math.cos((RunTime+i*4.5)/5);<br />ieDiv.all.c.all[0].style.left=Xpos+cntr*Math.sin((RunTime+i*4.5)/5);<br />} <br />cntr+=1;<br />RunTime+=speed;<br />window.status=RunTime;<br />stp=setTimeout('sv2()',10);<br />if (cntr>=100)<br />{<br />cntr=100;<br />speed=2.5;<br />for (i=0;i<ieDiv.all.c.all.length;i++)<br /> {<br />ieDiv.all.c.all[i].style.top=Ypos+cntr*Math.cos((RunTime-100)*i/90);<br />ieDiv.all.c.all[i].style.left=Xpos+cntr*Math.sin((RunTime-100)*i/90);<br /> }<br />}<br />if (RunTime>182)<br />{<br />speed=0.5;<br />for (i=0;i<ieDiv.all.c.all.length;i++)<br /> {<br />ieDiv.all.c.all[i].style.top=Ypos+xcntr*Math.cos(((RunTime-182)+i*4.5)/5)*Math.cos((RunTime-182)/5);<br />ieDiv.all.c.all[i].style.left=Xpos+xcntr*Math.sin(((RunTime-182)+i*4.5)/5);<br /> }<br />}<br />}<br />if (RunTime>210)<br />{<br />xcntr-=10;<br />}<br />if (document.layers)<br />_y=-window.innerWidth-90;<br />else if (document.all)<br />_y=-document.body.clientWidth-90;<br />if (xcntr <= _y)<br />{<br />RunTime=0;<br />speed=1;<br />cntr=0;<br />xcntr=100;<br />}<br />}<br />sv2()<br />//--><br /></SCRIPT><br />

没有评论: